I have a m2m relationship of Posts and Categories. A post can be in any 
number of categories, and a category can have any number of posts. This 
relation is defined on the Post model:

categories = relation(Category, lazy=True, secondary=PostCategory.__table__,
                          backref=backref('posts'))

PostCategory looks like this:

class PostCategory(orm.Base):
    post_id = Column(Integer, ForeignKey('posts.id'), primary_key=True)
    category_id = Column(Integer, ForeignKey(Category.id), primary_key=True)

When either of these two objects are deleted, I want to purge all records 
involving that object from the association table. Doing this manually is 
not an issue, but I'd like to code this behavior right into the class so as 
to keep the logic outside of the views.

I am using MyISAM on mysql, so the relevant section on 'ON DELETE CASCADE' 
isn't useful here.

Anyone know how to accomplish this?


-- 
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/-/J6XhNh1fZGMJ.
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.

Reply via email to