以下は、sqlalchemyのドキュメントです。SQLAlchemyアソシエーションオブジェクトの外部キーがプライマリキーとしてマークされているのはなぜですか?
お知らせ 最初のForeignKeyとしてマークされた関連クラスでleft_idとright_idのために、彼らがどのようにして、PRIMARY_KEY = Trueの
それは論理的に、彼らはへの外部キーがあるので、彼らは外部キーでなければならないように私には理にかなっています他の2つの親テーブルと子テーブル
これをプライマリキーにする目的は何ですか?
ここでは何が起こっていますか?説明してください。
class Association(Base):
__tablename__ = 'association'
left_id = Column(Integer, ForeignKey('left.id'), primary_key=True)
right_id = Column(Integer, ForeignKey('right.id'), primary_key=True)
extra_data = Column(String(50))
child = relationship("Child", back_populates="parents")
parent = relationship("Parent", back_populates="children")
class Parent(Base):
__tablename__ = 'left'
id = Column(Integer, primary_key=True)
children = relationship("Association", back_populates="parent")
class Child(Base):
__tablename__ = 'right'
id = Column(Integer, primary_key=True)
parents = relationship("Association", back_populates="child")