DDC-3977: BaseEntityPersister, different behavior between conditionStatement and selectStatement #4857

Open
opened 2026-01-22 14:50:33 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 2, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user razorness:

BasicEntityPersister::getSelectConditionStatementColumnSQL() needs to check for inheritance type before considering the usage of $classmetadata->fieldMappings[$field]['inherited'].

Otherwise BasicEntityPersister will use another table alias as the rest of the generated SQL statement. I came across this problem while I tried to extend an entity in another symfony bundle to get new associations working with it.

Just try following:

<?php
use Doctrine\ORM\Mapping as ORM;

/****
 * @ORM\Entity()
 * @ORM\Table()
 */
class Foo {

    /****
     * @var int
     *
     * @ORM\Id()
     * @ORM\Column(type="integer")
     */
    protected $id;

    /****
     * @var string
     *
     * @ORM\Column()
     */
    protected $title;       

    // ...
}

<?php
use Doctrine\ORM\Mapping as ORM;

/****
 * @ORM\Entity()
 * @ORM\Table()
 */
class Bar extends Foo {

    // ... add some OneToMany associations
}

<?php

// ...
$em->getRepository('Bar')->findOneBy(['title' => 'foobar']);

I cannot declare associations directly in Foo because existence of associations is not guaranteed in all scenarios where I use Foo.

Supporting such scenario would be great for modular systems on code and database level.

Originally created by @doctrinebot on GitHub (Nov 2, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user razorness: BasicEntityPersister::getSelectConditionStatementColumnSQL() needs to check for inheritance type before considering the usage of $classmetadata->fieldMappings[$field]['inherited']. Otherwise BasicEntityPersister will use another table alias as the rest of the generated SQL statement. I came across this problem while I tried to extend an entity in another symfony bundle to get new associations working with it. Just try following: ``` java <?php use Doctrine\ORM\Mapping as ORM; /**** * @ORM\Entity() * @ORM\Table() */ class Foo { /**** * @var int * * @ORM\Id() * @ORM\Column(type="integer") */ protected $id; /**** * @var string * * @ORM\Column() */ protected $title; // ... } ``` ``` java <?php use Doctrine\ORM\Mapping as ORM; /**** * @ORM\Entity() * @ORM\Table() */ class Bar extends Foo { // ... add some OneToMany associations } ``` ``` java <?php // ... $em->getRepository('Bar')->findOneBy(['title' => 'foobar']); ``` I cannot declare associations directly in Foo because existence of associations is not guaranteed in all scenarios where I use Foo. Supporting such scenario would be great for modular systems on code and database level.
admin added the Improvement label 2026-01-22 14:50:33 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4857