[DC-996] UPDATE query generate ambiguous statement Created: 13/Apr/11  Updated: 13/Apr/11

Status: Open
Project: Doctrine 1
Component/s: Query
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: John Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 2
Labels: None
Environment:

MAMP on MacBook Pro 10.6.7, with Symfony 1.4.9



 Description   

When creating an UPDATE query, the table names are not aliased like in a SELECT statement. This causes ambiguous column names when JOINING in an UPDATE.

E.g.
$q = $this->createQuery('st')
->update('SomeTable st')
->set('st.position','st.position + 1')
->leftJoin('st.SomeOtherTable sot ON st.some_id = sot.id')
->where('st.id <> ?', $someId)
->andWhere('sot.some_column = ?', $someValue)

The generated SQL for this is :
UPDATE some_table
LEFT JOIN some_other_table sot ON st.some_id = sot.id
SET position = position + 1, updated_at = 2011-04-13 11:01:03, updated_at = 2011-04-13 11:01:03
WHERE (id <> 4 AND some_column = 7)

Clearly here "updated_at" and "id" are ambiguous columns. Why the tables are not automatically aliased with unique aliases like in a SELECT statement, and the aliases written before the column name ?

Thanks.


Generated at Fri Aug 01 14:09:04 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.