On Aug 9, 2013, at 10:45 PM, Mark Eastwood <markeastwoo...@gmail.com> wrote:

> It is easier to describe in code than in words.

absolutely, this is much preferred.


> Can anyone please tell me if there is something that I am doing wrong? is 
> this a bug with sqlalchemy?

it's kind of a bug, yes, the biggest bug here is that the docs for 
query.update() are very underdetailed in this respect, as there is a huge 
caveat regarding multi-table mappings here.

your query will work on MySQL, Postgresql, and SQL Server if you do it like 
this:

updated = query.filter(Parent.id==Child.id).update({'value': 4})


this because an UPDATE is traditionally against a single table only, however in 
SQLA 0.8 the ability to support so-called "multiple table updates" was added, a 
feature supported in very different ways by these three backends.  So updating 
against "Child", which is really a combination of the "parent, child" tables 
particularly since your WHERE criteria is against the parent, puts both tables 
into the UPDATE statement, but the mechanism currently does not add the 
"joining" criteria for the Parent to Child.    Such an UPDATE wasn't even 
possible prior to 0.8 and also won't work on backends like SQLite or Oracle at 
all since they don't support multi-table updates.

These kinds of issues can be diagnosed by setting echo=True on your Engine, 
then looking to see what's actually going wrong with the query.

but we need a ticket for this in trac b.c. the docs don't even provide a hint 
of this.


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to