On Oct 18, 8:01 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > On Oct 18, 2011, at 10:03 AM, fribes wrote: > > > > > Hi all, > > > Despite some doc and web digging, I didn't find how to tell sqa to behave > > the way I want : > > on deletion on Peripheral, also delete in Actuator. > > > with the following code, the record in Actuator remains after a deletion, > > and a subsequent creation fails with IntegrityError. > > > class Peripheral(Base): > > __tablename__ = 'peripheral' > > id = Column(Integer, primary_key=True) > > label = Column(String(20), nullable=False) > > > __mapper_args__ = {'polymorphic_on': peripheral_type, > > 'polymorphic_identity': 'peripheral'} > > > class Actuator(Peripheral): > > __tablename__ = 'actuator' > > __mapper_args__ = {'polymorphic_identity': 'actuator'} > > id = Column(None, ForeignKey('peripheral.id'), primary_key=True) > > > duration = Column(Integer) > > > Any suggestion ? > > usually relationship() with cascade="all, delete-orphan" is used for this use > case, so that SQLAlchemy can maintain knowledge about the link between > Peripheral and Actuator. The other alternative is to use "ON DELETE CASCADE" > on the foreign key; this is part of the schema you'd generate in the database. > > Relevant docs: > > http://www.sqlalchemy.org/docs/orm/tutorial.html#configuring-delete-d...http://www.sqlalchemy.org/docs/core/schema.html#on-update-and-on-deletehttp://www.sqlalchemy.org/docs/orm/collections.html#using-passive-del... > > > > > Regards,
I forgot to mention I'm using SQLite, so ondelete="CASCADE" is not a option. Mike's suggestion is OK so far, I'll stick to it. Thanks and best regards. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.