Search code examples
mysqlsqlsymfonysql-updatedql

DQL Update multiple tables


I'm trying to update a row from some tables in one query. I've done:

        $this->getDoctrine()->getManager()
            ->createQuery('
            UPDATE eo, tw FROM       
            ProEntityOneBundle:EntityOne eo,
            ProEntityTwoBundle:EntityTwo tw
            SET eo.propertyOne = :newProperty,
                tw.propertyTwo = :newProperty
            WHERE eo.propertyOne = :oldProperty
                AND tw.propertyTwo = :oldProperty')
            ->setParameters(array('newProperty' => $newProperty, 'oldProperty' => $oldProperty))
            ->execute();

But I'm getting this error:

[Semantical Error] line 0, col 24 near 'eo, tw': Error: Class 'eo' is not defined.

What am I doing wrong? Is it possible to update some tables in one query with DQL?


Solution

  • This isn't possible. Each Doctrine query maps to a single SQL statement executed against the DB, and you can't update more than one table in a statement.