Hi Sergey, I'll give it a try, thanks !
On 2 June 2011 03:15, Sergey V. <[email protected]> wrote: > Hi, > > One easy/obvious improvement would be to delete all user's > "identifiers" and "groups" at once without iterating over them for > every user. Actually, iterating over the list of user_ids is not > necessary too I think. > > <code> > session.query(Identifier).filter(Identifier.user_id.in_(user_ids)).delete() > session.query(User).filter(User.id.in_(user_ids)).delete() > </code> > > I'm not sure about deleting "groups" in your code - I suppose you > don't want to delete the actual group but only the association between > the user and the group, i.e. the record from the intermediate table. > But the idea is the same - .filter(blah- > blah.user_id.in_(user_ids)).delete() > > An even better solution would be to set up proper cascade rules on > your relationships so all "dependent" items are deleted automatically > when a user is deleted. Then the method will be a one-liner: > > <code> > session.query(User).filter(User.id.in_(user_ids)).delete() > </code> > > > -- 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.
