Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 3 comments

1 participant

@doctrinebot

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

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by romanb:

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

@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.