Hi all,
We have a list of polymorphic objects from which delete object does not
work, not matter what we try.
The situation:
class ItemGroup(Base):
__tablename__ = 'item_group'
__table_args__ = (
UniqueConstraint('model_id', 'item_group_color_id',
name='unique_model_id_item_group_color_id_uc'),
)
id = Column(Integer, primary_key=True)
items = relationship("Item", back_populates="item_group")
class Item(Base):
__tablename__ = 'item'
id = Column(Integer, primary_key=True)
item_group_id = Column(ForeignKey('item_group.id'), nullable=False,
index=True)
item_group = relationship('ItemGroup', back_populates="items",
uselist=False)
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'polymorphic_on': item_type
}
class ItemMeta(Item):
__tablename__ = 'item_meta'
id = Column(Integer, ForeignKey('item.id', ondelete="CASCADE"),
primary_key=True)
meta_name = Column(String(255, collation), nullable=False)
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
The problem occurs after a delete:
session.query(ItemMeta).filter_by(item_group=ig).delete()
Now, querying the child works fine:
session.query(ItemMeta).filter_by(item_group=ig).all()
[]
But querying the parent:
test_fixtures.session.query(Item).filter_by(item_group=ig).all()
Give: Instance '<ItemMeta at 0x7f0b024afcf8>' has been deleted, or its row is
otherwise not present.
In the database I can see the lingering parent objects. I guess that I have to
use something like
delete-orphan, but as I dont have a relation from child to father, so now I'm
stuck.
Any ideas are welcome.
Kind regards,
Nacho
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/7dea2eaa-6390-4a54-abd5-fae925727c17%40googlegroups.com.