2
使用SQLAlchemy 1.0.13,是否可以從繼承類中刪除relationship join?使用繼承刪除SQLAlchemy關係
在下一個最小的工作示例中,我有一個父母和兩種孩子。子類與父類有關係。 AlienChild從Child獲取所有屬性,但我想放棄關係。這可能嗎?
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer,
ForeignKey('parent.id',
ondelete='CASCADE'),
nullable=False)
parent = relationship('Parent',
backref=backref(
'children', cascade="all, delete-orphan"),
foreign_keys=[parent_id],
single_parent=True)
class AlienChild(Child):
__tablename__ = 'alienchild'
parent = droprelationship('Parent')