用related_name 属性制定名字就可以了。对应在表中的字段就是 sample1_id, sample2_id
class Company(Base):
__tablename__ = 'company'
id = Column(Integer, primary_key=True)
name = Column(String(50), nullable=False)
class Employee(Base):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
company_id = Column(Integer, ForeignKey('company.id'), nullable=False)
stakeholder_id = Column(Integer, ForeignKey('company.id'), nullable=False)
company = relationship("Company", foreign_keys=[company_id])
stakeholder = relationship("Company", foreign_keys=[stakeholder_id])
关注公众号「Python之禅」,回复「1024」免费获取Python资源