session query TFolder id TFolderAttributes name func count folderSetRe

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
q = session.query(TFolder.id, TFolderAttributes.name,\
func.count(folderSetRecordClassLevel2.id).label('folderCount'),\
func.count(chartUserAttribDictClass.Value).label('chartCount')).\
join(TCollection._TBaseElement__attributes).\
join(TCollection._TBaseCollectionInfo__folderSet).\
join(TFolderSet._TBaseCompound__children_records).\
join((TFolder, folderSetRecordClass.item)).\
join(TFolder._TBaseElement__attributes).\
join((folderSetLevel2, TFolder._TBaseCollectionInfo__folderSet)).\
outerjoin((folderSetRecordClassLevel2, folderSetLevel2._TBaseCompound__children_records)).\
join((TChartSet, TFolder._TBaseCollectionInfo__chartSet)).\
outerjoin((chartSetRecordClass, TChartSet._TBaseCompound__children_records)).\
outerjoin((TChart, chartSetRecordClass.item)).\
outerjoin((TChartAttributes, TChart._TBaseElement__attributes)).\
outerjoin ((chartUserAttribDictClass, and_(
TChartAttributes.id == chartUserAttribDictClass.ChartAttributes_id,
chartUserAttribDictClass.Key == u"Type",
chartUserAttribDictClass.Value.in_(contentType)))).\
filter(TCollection.id == collectionId).\
group_by(TFolder.id).\
group_by(TFolderAttributes.name).\
group_by(folderSetRecordClass.position).\
order_by(folderSetRecordClass.position)