私は次のようなsqlalchemyで自己参照の多対多の関係(Lineは多くの親行と多くの子行を持つことができることを意味します)を作成しようとしています:
Base = declarative_base()
class Association(Base):
__tablename__ = 'association'
prev_id = Column(Integer, ForeignKey('line.id'), primary_key=True)
next_id = Column(Integer, ForeignKey('line.id'), primary_key=True)
class Line(Base):
__tablename__ = 'line'
id = Column(Integer, primary_key = True)
text = Column(Text)
condition = Column(Text)
action = Column(Text)
next_lines = relationship(Association, backref="prev_lines")
class Root(Base):
__tablename__ = 'root'
name = Column(String, primary_key = True)
start_line_id = Column(Integer, ForeignKey('line.id'))
start_line = relationship('Line')
しかし、次のエラーが発生します:sqlalchemy.exc.ArgumentError:リレーションシップLine.next_linesの親/子テーブル間の結合条件を判別できませんでした。'primaryjoin'式を指定します。'secondary'が存在する場合は、'secondaryjoin'も必要です。
私がこれをどのように改善できるか知っていますか?