I have 2 tables that are referenced via a relationship() flag, I need to
figure out how to cascade delete them or delete them when their parent is
deleted.
My DB Structure:
learn_tags = Table('learn_tags', Entity.metadata,
Column('profile_pk', Integer, ForeignKey('user_profile.pk')),
Column('skill_tag_pk', Integer, ForeignKey('skill_tag.pk'))
)
teach_tags = Table('teach_tags', Entity.metadata,
Column('profile_pk', Integer, ForeignKey('user_profile.pk')),
Column('skill_tag_pk', Integer, ForeignKey('skill_tag.pk'))
)
class SkillTag(Entity):
name = Column(UnicodeText, nullable=False, unique=True)
class UserProfile(Entity):
learn = relationship("SkillTag", secondary=learn_tags)
teach = relationship("SkillTag", secondary=teach_tags)
I want to be able to delete a SkillTag and delete all of the entries in the
learn_tags and teach_tags. I'm not sure where to place the cascade for
this to work.
I'm currently doing:
del1 = learn_tags.delete().where(
learn_tags.c.skill_tag_pk == pk
)
del2 = teach_tags.delete().where(
teach_tags.c.skill_tag_pk == pk
)
DBSession.execute(del1)
DBSession.execute(del2)
skill = DBSession.query(SkillTag).get(pk)
which works but is kind of dirty.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/6c2mefWpTdMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.