如何在同一个类之间建立多个一对一的关系?
例如,我想要一个“Location”类,它有两种不同类型的“LoadDetail”,我将其命名为“pickup_details”和“delivery_details”。有人可以解释一下吗?
这是我到目前为止 -
class Location(db.Model):
id = db.Column(db.Integer, primary_key=True)
pickup_detail = db.relationship("LoadDetail", foreign_keys='LoadDetail.pickup_id', backref='pickup_location')
delivery_detail = db.relationship("LoadDetail", foreign_keys='LoadDetail.delivery_id', backref='delivery_location')
class LoadDetail(db.Model):
id = db.Column(db.Integer, primary_key=True)
pickup_id = db.Column(db.Integer, db.ForeignKey('location.id'))
delivery_id = db.Column(db.Integer, db.ForeignKey('location.id'))
谢谢!