The delete method of query supports bulk deletes.
In your case it might be something like

session.query(Users).filter(User.officeid==office.id).delete()

Any query can be used; there are probably more elegant ways to take
advantage of the relation 'users' also.

Make sure you read the documentation for Query.delete() to understand the
impact of the 'synchronize_session' keyword


-- 
Mike Conley



On Wed, Aug 19, 2009 at 5:54 PM, <[email protected]> wrote:

>
> Hello,
>
> I have several objects from a relation that I'd like to delete. To me,
> this would be a natural syntax:
>
> session.delete(office.users)
>
> to delete all of the "user" objects. I get this error when doing this:
>
>     raise exc.UnmappedInstanceError(instance)
> sqlalchemy.orm.exc.UnmappedInstanceError: Class
> 'sqlalchemy.orm.collections.InstrumentedList' is not mapped
>
> Took me a while to figure out that delete() didn't work like that. I
> use this instead:
>
> [session.delete(x) for x in office.users]
>
> Can session.delete() be made to work as above (or at the very least
> produce a better error message)?
>
> Cheers,
> Demitri
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to