Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-448

Cannot select rows from chield table by JoinColumn in @InheritanceType("JOINED") parent table

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: DQL, ORM
    • Security Level: All
    • 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

        Activity

        Hide
        Guilherme Blanco added a comment -
        Show
        Guilherme Blanco added a comment - In http://github.com/doctrine/doctrine2/commit/56a8f5cd5353908b815607a6e089201c95e01e6c this issue was fixed! Thanks for the report!
        Hide
        Roman S. Borschel added a comment -

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

        Show
        Roman S. Borschel added a comment - The testcase is irritating though, because connectedClassId is an object, not an id.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Uvarov Michael
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: