[DDC-448] Cannot select rows from chield table by JoinColumn in @InheritanceType("JOINED") parent table Created: 20/Mar/10  Updated: 13/Apr/10  Resolved: 12/Apr/10

Status: Closed
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Critical
Reporter: Uvarov Michael Assignee: Roman S. Borschel
Resolution: Fixed Votes: 0
Labels: None


 Description   

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  ) 
       )
       ->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



 Comments   
Comment by Guilherme Blanco [ 12/Apr/10 ]

In http://github.com/doctrine/doctrine2/commit/56a8f5cd5353908b815607a6e089201c95e01e6c this issue was fixed!

Thanks for the report!

Comment by Roman S. Borschel [ 13/Apr/10 ]

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

Generated at Fri Aug 29 18:16:17 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.