DDC-448: Cannot select rows from chield table by JoinColumn in @InheritanceType("JOINED") parent table #556

Closed
opened 2026-01-22 12:42:26 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 20, 2010).

Jira issue originally created by user freeakk:

This bug is connected with http://www.doctrine-project.org/jira/browse/DDC-416
I have this schema.

/****
 * @Entity
 * @InheritanceType("JOINED") 
 * @DiscriminatorColumn(name="discr", type="smallint")
 * @DiscriminatorMap({
 * "0" = "mainTable",
 * "1" = "SubTable"
 * })
 */
class mainTable
{   
    /****
     * @Id
     * @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
     * @ManyToOne(targetEntity="connectedClass",  cascade={"all"}, fetch="EAGER")
     * @JoinColumn(name="connectedClassId", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE", nullable=true)
     */
    private $connectedClassId;
}

/****
 * @Entity
 * @Table(name="connectedClass")
 * @HasLifecycleCallbacks
 */
class connectedClass
{   
    /****
     * @Id
     * @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id; // connected with mainTable
}

/****
 * @Entity
 * @Table(name="SubTable")
 */
class SubTable extends mainTable
{
}


$qb->select(array('b'))
       ->from('SubTable', 'b')
       ->where(
           $qb->expr()->eq('b.connectedClassId', '?1') // select by JoinColumn field does not work
                                                                                          // select by normal column work (after http://www.doctrine-project.org/jira/browse/[DDC-416](http://www.doctrine-project.org/jira/browse/DDC-416)  ) 
       )
       ->setParameter(1, $value); // $value - const or connectedClass object


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'i1_.connectedClassId' in 'where clause'' in /var/www/shelly/library/Doctrine/DBAL/Connection.php:573
Stack trace:
#0 /var/www/shelly/library/Doctrine/DBAL/Connection.php(573): PDOStatement->execute(Array)
#1 /var/www/shelly/library/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php(42): Doctrine\DBAL\Connection->execute('SELECT p0_.id A...', Array)
#2 /var/www/shelly/library/Doctrine/ORM/Query.php(231): Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(Object(Doctrine\DBAL\Connection), Array)
#3 /var/www/shelly/library/Doctrine/ORM/AbstractQuery.php(514): Doctrine\ORM\Query->_doExecute(Array)
#4 /var/www/shelly/library/Doctrine/ORM/AbstractQuery.php(391): Doctrine\ORM\AbstractQuery->execute(Array, NULL)

So, we cannot select rows by JoinColumn from Inheritance tables, because doctrine selects SubTable.connectedClassId field, not mainTable.connectedClassId

This bug was fix in http://www.doctrine-project.org/jira/browse/DDC-416 patch, but it was not commited. I may write unit test for this problem

Originally created by @doctrinebot on GitHub (Mar 20, 2010). Jira issue originally created by user freeakk: This bug is connected with http://www.doctrine-project.org/jira/browse/[DDC-416](http://www.doctrine-project.org/jira/browse/DDC-416) I have this schema. ``` /**** * @Entity * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="smallint") * @DiscriminatorMap({ * "0" = "mainTable", * "1" = "SubTable" * }) */ class mainTable { /**** * @Id * @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ private $id; /**** * @ManyToOne(targetEntity="connectedClass", cascade={"all"}, fetch="EAGER") * @JoinColumn(name="connectedClassId", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE", nullable=true) */ private $connectedClassId; } /**** * @Entity * @Table(name="connectedClass") * @HasLifecycleCallbacks */ class connectedClass { /**** * @Id * @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; // connected with mainTable } /**** * @Entity * @Table(name="SubTable") */ class SubTable extends mainTable { } $qb->select(array('b')) ->from('SubTable', 'b') ->where( $qb->expr()->eq('b.connectedClassId', '?1') // select by JoinColumn field does not work // select by normal column work (after http://www.doctrine-project.org/jira/browse/[DDC-416](http://www.doctrine-project.org/jira/browse/DDC-416) ) ) ->setParameter(1, $value); // $value - const or connectedClass object Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'i1_.connectedClassId' in 'where clause'' in /var/www/shelly/library/Doctrine/DBAL/Connection.php:573 Stack trace: #0 /var/www/shelly/library/Doctrine/DBAL/Connection.php(573): PDOStatement->execute(Array) #1 /var/www/shelly/library/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php(42): Doctrine\DBAL\Connection->execute('SELECT p0_.id A...', Array) #2 /var/www/shelly/library/Doctrine/ORM/Query.php(231): Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(Object(Doctrine\DBAL\Connection), Array) #3 /var/www/shelly/library/Doctrine/ORM/AbstractQuery.php(514): Doctrine\ORM\Query->_doExecute(Array) #4 /var/www/shelly/library/Doctrine/ORM/AbstractQuery.php(391): Doctrine\ORM\AbstractQuery->execute(Array, NULL) ``` So, we cannot select rows by JoinColumn from Inheritance tables, because doctrine selects SubTable.connectedClassId field, not mainTable.connectedClassId This bug was fix in http://www.doctrine-project.org/jira/browse/[DDC-416](http://www.doctrine-project.org/jira/browse/DDC-416) patch, but it was not commited. I may write unit test for this problem
admin added the Bug label 2026-01-22 12:42:26 +01:00
admin closed this issue 2026-01-22 12:42:26 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 12, 2010):

Comment created by @guilhermeblanco:

In 56a8f5cd53 this issue was fixed!

Thanks for the report!

@doctrinebot commented on GitHub (Apr 12, 2010): Comment created by @guilhermeblanco: In http://github.com/doctrine/doctrine2/commit/56a8f5cd5353908b815607a6e089201c95e01e6c this issue was fixed! Thanks for the report!
Author
Owner

@doctrinebot commented on GitHub (Apr 12, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Apr 12, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Apr 13, 2010):

Comment created by romanb:

The testcase is irritating though, because connectedClassId is an object, not an id.

@doctrinebot commented on GitHub (Apr 13, 2010): Comment created by romanb: The testcase is irritating though, because connectedClassId is an object, not an id.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#556