【发布时间】:2015-10-22 15:50:12
【问题描述】:
假设我有两个表(使用 SQLAlchemy)供父母和孩子使用:
class Child(Base):
__tablename__ = 'Child'
id = Column(Integer, primary_key=True)
is_boy = Column(Boolean, default=False)
parent_id = Column(Integer, ForeignKey('Parent.id'))
class Parent(Base):
__tablename__ = 'Parent'
id = Column(Integer, primary_key=True)
children = relationship("Child", backref="parent")
如何查询属性以了解父母是否有男孩的孩子?希望在 pandas 中使用此列,但不知道如何有效地查询它。我的直觉是创建一个 SQLALchemy 混合属性 has_a_boy_child,但我不确定如何定义混合属性或匹配表达式。谢谢!
【问题讨论】:
标签: python sql sqlalchemy