python - SQL Alchemy Query with Eagerly Loaded Relationships? -
i'm having trouble using sa's eager relationship loading within query.
i have 2 tables declared so:
class score(base): __tablename__ = 'score' school = relationship("school", backref='score') schoolkey = column('schoolkey', integer, primary_key=true) class school(base): __tablename__ = 'school' schoolkey = deferred(column('schoolkey', integer, primary_key=true)) schoolname = column('schoolname', string) schooldistrict = deferred(column('schooldistrict', string), group = 'district') schooldistrictid = deferred(column('schooldistrictid', integer), group = 'district')
i want query score table filter condition coming school table concisely possible. have relationship eagerly loaded.
right when query cannot work:
session.query(score).filter(school.schoolname == 'randomname')
(this crashes computer) anyone have idea how work?
context: know sounds trivial example, score fact table @ heart of >10 tables. want avoid writing 10 .join parts query filter. want avoid this:
session.query(score).join(school).filter(school.schoolname == 'randomname')
temporary solution: accepting need write join dimension tables:
session.query(score).join(school).filter(school.schoolname == 'randomname')
Comments
Post a Comment