0
我使用SQLAlchemy来表示作者之间的关系。我希望有与其他作者相关的作者(coauthorshp),并且在关系中有额外的数据,因此通过作者a
我可以找到他们的合着者。从表到SQLAlchemy自身的多对多关系
如何,这是两个不同的对象之间进行的是:
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(80))
child = relationship('Child', backref='parent_assocs')
class Parent(Base):
__tablename__ = 'left'
id = Column(Integer, primary_key=True)
children = relationship('Association', backref='parent')
class Child(Base):
__tablename__ = 'right'
id = Column(Integer, primary_key=True)
,但我会怎么做这在我的情况?
共同作者的性质是它是双向的。所以,当通过coauthoship对象将元组(id_left, id_right)
插入到coauthorship表中时,是否还有一种方法可以轻松插入反向关系?我在问,因为我想使用关联代理。
你能举一个你究竟想要做什么的例子吗?阅读你的问题是有道理的,但需要更多的信息。 – CodeLikeBeaker