On Jan 5, 2012, at 9:57 AM, Michael Hipp wrote: > Working from the many-many example in the tutorial [1], it has an association > table like this: > > post_keywords = Table('post_keywords', Base.metadata, > Column('post_id', Integer, ForeignKey('posts.id')), > Column('keyword_id', Integer, ForeignKey('keywords.id')) > ) > > Normally to just empty everything from a table I'd do this: > > session.query(BlogPost).delete()
if you use ON DELETE CASCADE on the foreign keys referred to by post_keywords, then those rows will delete automatically when saying query(BlogPost).delete(). if you don't have ON DELETE CASCADE set up, then you'd need to delete each BlogPost individually: for post in query(BlogPost): session.delete(post) or otherwise remove the associations to each keyword. -- 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.