Many-to-many self-referential relationship in sqlalchemy

后端 未结 1 2141
孤街浪徒
孤街浪徒 2021-02-19 17:02

I\'m trying to make a self-referential many-to-many relationship (it means that Line can have many parent lines and many child lines) in sqlalchemy like this:

Ba         


        
相关标签:
1条回答
  • 2021-02-19 17:15

    You should just need:

    prev_lines = relationship(
        Association,
        backref="next_lines",
        primaryjoin=id==Association.prev_id)
    

    Since this specifies the next_lines back reference there is no need to have a next_lines relationship.

    You can also do this using the remote_side parameter to a relationship: http://www.sqlalchemy.org/trac/browser/examples/adjacency_list/adjacency_list.py

    0 讨论(0)
提交回复
热议问题