我想知道requiresQuery是否只会在被调用时执行,或者只在您对该表进行查询时执行。
class SomeTable(Base):
...
someJson = Column(Text)
...
@property
def requiresQuery(self):
filterValue = getValueFromJson(self.someJson)
someQuery = session.query(OtherTable).filter(OtherTable.filter == filterValue)
return getValue(someQuery)
现在使用该表:
# Query SomeTable and never ask for the value
session.query(SomeTable).one().someJson
# Does the requiresQuery execute here?
# Or does it need to be called explicitly
session.query(SomeTable).one().requiresQuery
# requiresQuery has been called here.