📜  sqlalchemy 一对多 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:39.672000             🧑  作者: Mango

代码示例1
class Parent(Base):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)
    children = relationship("Child", back_populates="parent")

class Child(Base):
    __tablename__ = 'child'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('parent.id'))
    parent = relationship("Parent", back_populates="children")