我有一个类似的课程:
class Component(Base):
__tablename__ = 'components'
id = Column(Integer, primary_key=True)
.
.
.
.
alternate1_id = Column(Integer, foreignkey("components.id"), nullable=True)
alternate2_id = Column(Integer, foreignkey("components.id"), nullable=True)
alternate3_id = Column(Integer, foreignkey("components.id"), nullable=True)
def __init__(self, catalog_number, component_type, manufacturer_pn, description):
self.catalog_number = catalog_number
self.component_type = component_type
self.manufacturer_pn = manufacturer_pn
self.description = description
def __repr__(self):
return "<Component('%s', '%s', '%s', '%s')>" % (self.catalog_number,
self.component_type,
Alternate1、2 和 3 是可选字段,它们指向当前实例的替代组件。
如何创建三个关系,每个关系都引用每个 id?