1class Parent(Base):
2 __tablename__ = 'parent'
3 id = Column(Integer, primary_key=True)
4 children = relationship("Child", back_populates="parent")
5
6class Child(Base):
7 __tablename__ = 'child'
8 id = Column(Integer, primary_key=True)
9 parent_id = Column(Integer, ForeignKey('parent.id'))
10 parent = relationship("Parent", back_populates="children")
1association_table = Table('association', Base.metadata,
2 Column('left_id', Integer, ForeignKey('left.id')),
3 Column('right_id', Integer, ForeignKey('right.id'))
4)
5
6class Parent(Base):
7 __tablename__ = 'left'
8 id = Column(Integer, primary_key=True)
9 children = relationship(
10 "Child",
11 secondary=association_table,
12 back_populates="parents")
13
14class Child(Base):
15 __tablename__ = 'right'
16 id = Column(Integer, primary_key=True)
17 parents = relationship(
18 "Parent",
19 secondary=association_table,
20 back_populates="children")
1t = Table("remote_table", metadata,
2 Column("remote_id", ForeignKey("main_table.id"))
3)