On Monday 20 April 2009 19:00:20 Christoph Zwerschke wrote:
> Dan F schrieb:
> > If I need to update a property on a set of objects, what's the
> > recommended way to do this?  Ideally it would be simple, but not require
> > excessive querying.  I could do:
> >
> > db.query(Email).get(id).spam = True
> >
> > but that requires N selects and N updates.
>
> You could do something like this:
>
> for email in db.query(Email).filter(Email.email_id.in_(id_list)):
>      email.password = 'changed'
>
> This would cause only one select, but still N updates when the database
> session is flushed.
>
> > I could do:
> >
> > email_table.update().where(email_table.c.email_id.in_(id_list)).values(sp
> >am=True))
> >
> > But that seems to require some way of committing the result.  I haven't
> > found out how to do that, and I'm not sure this is the "sanctioned" way
> > of doing this anyway.
> >
> > Any guidance is appreciated.
>
> That should work; the commit happens automatically if you're using an up
> to date version of zope.sqlalchemy.

Are you sure about that? I threw out z.sa because it did *not* recognize 
altered sessions & issued no commit in this case.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to