我想过滤由类的关系生成的查询,而无需手动进行联接。
给出两个模型类:
class Parent(Base):
id = Column(Integer, primary=True)
gender = Column(String) # there are more than two genders!
class Child(Base):
id = Column(Integer, primary=True)
parents = db.relationship(Parent, secondary=child_parent_association, backref="parents")
我正在搜索与以下语法相似的内容:
mother_count = child_object.parents.filter(Parent.gender=="Female").count()
当我可以将child_object.parents
当作Query
对象而不是InstrumentedList
时。