I have the following models:
class CRRun(Base):
...
crID = Column(u'CR_ID', INTEGER(), ForeignKey(CR.id), primary_key=True,
nullable=False)
cr = relationship(CR, backref=backref("CR_RUN", uselist=False))
...
class CR(Base):
...
id = Column(u'CR_ID', INTEGER(), primary_key=True, nullable=False)
state = Column(u'STATE', VARCHAR(20))
...
I am then trying to do the following:
state = 'some value'
crsRuns = Session.query(CRRun)
crsRuns = crsRuns.options(eagerload('cr'))
.filter(CRRun.cr != None)
.filter(CRRun.cr.state.like('%' + state + '%'))
However, this causes the following error:
AttributeError: Neither ‘InstrumentedAttribute’ object nor ‘Comparator’ object has an attribute ‘state’
How can I filter my query by the value of a column in a table that’s connected to the table I’m querying via a foreign key?
I ended up doing the following: