Self-Referential Association Relationship SQLalchemy

后端 未结 4 1275
南笙
南笙 2020-12-17 03:39

In my flask application with flask-sqlalchemy i need to create association between two contact here is my Contact model

class Contact(db.Model):         


        
4条回答
  •  遥遥无期
    2020-12-17 04:01

    it seems that if you change the to_contacts to something like below, your problem will be solved:

    to_contacts = db.relationship('Contact',
                                  secondary='ContactRelation',
                                  primaryjoin='id==contactrelation.from_contact_id',
                                  secondaryjoin='id==contactrelation.to_contact_id',
                                  backref='from_contacts')
    

提交回复
热议问题