On 2012-01-05 1:24 PM, Michael Bayer wrote:
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'))
)
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().
Thanks, Michael. Setting ondelete='cascade' works well.
Is there a call for Table() objects that is equivalent to the
sess.query(Base).delete() way of deleting everything?
I have some possible occasions to do a "brute force" cleanup (e.g. unit
testing) but I'd prefer not having to revert to SQL.
Thanks,
Michael
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
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.