I am trying to query across 4 tables. They are all bound by foreign keys and they all have relationships defined. The problem I am having is that I can't seem to get the value I'm after.
I have 4 tables:
TDeviceReport:
ixDeviceReport(int, primary key)
ixDeviceType(int, foreign key)
ixReportType(int, foreign key)
TReportType:
ixReportType(int, primary key)
sReportType(string)
TReportSection
ixReportSection(int, primary key)
ixReportType(int, foreign key)
ixSection(int, foreign key)
and TSection: ixSection(int, primary key) sSection(string)
I am trying to get all the sections names (TSection.sSection) belonging to a deviceTypeID. The problem is I'm somewhat new to sqlAlchemy and not sure how to go about doing this. I've tried to set up a query but I'm not getting any results.
for section in DBSession.query(TDeviceReport, TReportType, TReportSection, TSection).join(TReportType).join(TReportSection).join(TSection).filter(TDeviceReport.ixDeviceType==deviceTypeID).all():
print "------------------------------------------------"
print "section : " + str(section )
any guidance would be appreciated
EDIT I redid the query a bit and this is the result that it prints
#get section headers
sections = []
for section in DBSession.query(TSection.sSection).join(TReportSection).join(TReportType).join(TDeviceReport).filter(TDeviceReport.ixDeviceType==deviceTypeID).all():
sections.append(str(section[0]))
print "section: " + str(section) + "------------------------------------------"
Printed results:
section: (u'Trip Unit Results',)------------------------------------------
section: (u'Generic Header',)------------------------------------------
section: (u'Circuit Breaker Data',)------------------------------------------
section: (u'Trip Unit Data',)------------------------------------------
section: (u'Sensor Data',)------------------------------------------
section: (u'Insulation Resistance',)------------------------------------------
section: (u'Contact Resistance',)------------------------------------------
section: (u'Breaker Inspection',)------------------------------------------
section: (u'Cell Inspection',)------------------------------------------