doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.93k stars 2.51k forks source link

Update Sql on inheritance Entity : error #6528

Open ldesmeules opened 7 years ago

ldesmeules commented 7 years ago

Error in sql query on inheritanceType "JOINED" Example on my table Rdv

/**
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="typeRdv", type="string")
 * @ORM\DiscriminatorMap({"simple" = "Rdv", "date" = "RdvDate"})
 */

With query:

$this->_em->createQuery(
    'UPDATE AppBundle:Rdv r SET
        r.time = (
            SELECT t FROM AppBundle:Time t JOIN t.rangeTime rt
            WHERE t.time = r.saveTime
                AND rt.date = r.saveDate
                AND rt.specialist = r.saveSpecialist
        )
     WHERE r.time IS NULL'
) ;

Queries sql are generated with error

CREATE TEMPORARY TABLE rdv_id_tmp (id INT NOT NULL);
INSERT INTO rdv_id_tmp (id) SELECT t0.id FROM rdv t0 LEFT JOIN rdv_date x0_ ON t0.id = x0_.id WHERE (t0.time_id IS NULL);
UPDATE rdv SET time_id = (SELECT x1_.id FROM time x1_ INNER JOIN range_time x2_ ON x1_.range_time_id = x2_.id ) WHERE x1_.time = t0.saveTime AND x2_.date = t0.saveDate AND x2_.specialist_id = t0.save_specialist_id) WHERE (id) IN (SELECT id FROM rdv_id_tmp);

SQLSTATE[42S22]: Column not found: 1054 Champ 't0.saveTime' inconnu dans where clause

I solved with modification follow in file "MultiTableUpdateExecutor.php" Line 109

$updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class, $platform) . ' SET ';

change to

$updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class, $platform) . ' t0 SET ';
lcobucci commented 7 years ago

@ldesmeules could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.

You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket