0
所以,如果我有兩個SQLAlchemy的表像如何使用子查詢篩選一對多關係中的sqlalchemy查詢?
class Parent
id = Column(Integer, primary_key=True)
children = relationship('Child', lazy='joined', backref=backref('parent', lazy='joined'))
class Child
id = Column(Integer, primary_key=True)
age = Column(Integer)
我如何找到所有已至少有一個孩子隨着年齡> 10的父母?
我已經試過這樣的事情,雖然這不工作:
Session.query(Parent.id).filter(func.count(Parent.children.filter(Child.age >= 10)) > 0)
嘗試'backref = backref('parent',lazy ='dynamic'))' – 2015-02-09 21:55:01