Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      We have a set of models that use Single Table inheritance and we are trying to select all objects of one type:

      /**
       * @Entity
       * @InheritanceType("SINGLE_TABLE")
       * @DiscriminatorColumn(name="type", type="string")
       * @DiscriminatorMap({"Child"="Child", "OtherChild"="OtherChild"})
      */
      abstract class ParentModel
      {
          /**
           * @Id @Column(name="id", type="integer")
           * @GeneratedValue(strategy="AUTO")
           */
          protected $id;
      
          /** @Column(type="string") */
          public $property;
      
          function getId() {return $this->id;}
      }
      
      abstract class SubParent extends ParentModel
      {
      }
      
      /**
       * @Entity
       */
      class Child extends SubParent
      {
          /** @Column(type="string") */
          public $anotherProperty;
      }
      
      /**
       * @Entity
       */
      class OtherChild extends SubParent
      {
          /** @Column(type="string") */
          public $someOtherProperty;
      }
      

      Now to query for all of the Child objects we do:

      $children = $em->getRepository('Child')->findall();
      foreach($children AS $child) {
          echo $child->getId();
      }
      

      but we get "Notice: Undefined index: id in ./Doctrine/ORM/UnitOfWork.php on line 1727" on the finAll() call and the objects that aren't of the correct type have their properties nulled out. This is because the query that is being executed doesn't have any conditionals for the type of model it's looking for and the ORM doesn't check to make sure that the object is of the correct type.

      This could be solved by having conditionals in the SQL query (chaining a bunch of 'or' statements for all of the child objects) or by pulling back all of the objects and then filtering out what isn't of the correct type. Unfortunately neither solution seems ideal.

      I'll try to make a test case for this then.

        Issue Links

          Activity

          mridgway Michael Ridgway created issue -
          Hide
          mridgway Michael Ridgway added a comment -

          Adding another child class just to be clear.

          Show
          mridgway Michael Ridgway added a comment - Adding another child class just to be clear.
          mridgway Michael Ridgway made changes -
          Field Original Value New Value
          Description We have a set of models that use Single Table inheritance and we are trying to select all objects of one type:

          {code}
          /**
           * @Entity
           * @InheritanceType("SINGLE_TABLE")
           * @DiscriminatorColumn(name="type", type="string")
           * @DiscriminatorMap({"Child"="Child"})
          */
          abstract class ParentModel
          {
              /**
               * @Id @Column(name="id", type="integer")
               * @GeneratedValue(strategy="AUTO")
               */
              protected $id;

              /** @Column(type="string") */
              public $property;

              function getId() {return $this->id;}
          }

          abstract class SubParent extends ParentModel
          {
          }

          /**
           * @Entity
           */
          class Child extends SubParent
          {
              /** @Column(type="string") */
              public $anotherProperty;
          }
          {code}

          Now to query for all of the Child objects we do:

          {code}
          $children = $em->getRepository('Child')->findall();
          foreach($children AS $child) {
              echo $child->getId();
          }
          {code}

          but we get "Notice: Undefined index: id in ./Doctrine/ORM/UnitOfWork.php on line 1727". This is because the query that is being executed doesn't have any conditionals for the type of model it's looking for and the ORM doesn't check to make sure that the object is of the correct type.

          This could be solved by having conditionals in the SQL query (chaining a bunch of 'or' statements for all of the child objects) or by pulling back all of the objects and then filtering out what isn't of the correct type. Unfortunately neither solution seems ideal.

          I'll try to make a test case for this then.
          We have a set of models that use Single Table inheritance and we are trying to select all objects of one type:

          {code}
          /**
           * @Entity
           * @InheritanceType("SINGLE_TABLE")
           * @DiscriminatorColumn(name="type", type="string")
           * @DiscriminatorMap({"Child"="Child", "OtherChild"="OtherChild"})
          */
          abstract class ParentModel
          {
              /**
               * @Id @Column(name="id", type="integer")
               * @GeneratedValue(strategy="AUTO")
               */
              protected $id;

              /** @Column(type="string") */
              public $property;

              function getId() {return $this->id;}
          }

          abstract class SubParent extends ParentModel
          {
          }

          /**
           * @Entity
           */
          class Child extends SubParent
          {
              /** @Column(type="string") */
              public $anotherProperty;
          }

          /**
           * @Entity
           */
          class OtherChild extends SubParent
          {
              /** @Column(type="string") */
              public $someOtherProperty;
          }
          {code}

          Now to query for all of the Child objects we do:

          {code}
          $children = $em->getRepository('Child')->findall();
          foreach($children AS $child) {
              echo $child->getId();
          }
          {code}

          but we get "Notice: Undefined index: id in ./Doctrine/ORM/UnitOfWork.php on line 1727" on the finAll() call and the objects that aren't of the correct type have their properties nulled out. This is because the query that is being executed doesn't have any conditionals for the type of model it's looking for and the ORM doesn't check to make sure that the object is of the correct type.

          This could be solved by having conditionals in the SQL query (chaining a bunch of 'or' statements for all of the child objects) or by pulling back all of the objects and then filtering out what isn't of the correct type. Unfortunately neither solution seems ideal.

          I'll try to make a test case for this then.
          Hide
          romanb Roman S. Borschel added a comment -

          Related to DDC-497 ? Of course there should be conditionals in the query when querying for a subtype. It really surprises me that this seems not to be the case. Maybe there has been some regression.

          Show
          romanb Roman S. Borschel added a comment - Related to DDC-497 ? Of course there should be conditionals in the query when querying for a subtype. It really surprises me that this seems not to be the case. Maybe there has been some regression.
          Hide
          mridgway Michael Ridgway added a comment -

          Attached a unit test that may or may not work.

          It looks to be a similar issue for sure.

          Show
          mridgway Michael Ridgway added a comment - Attached a unit test that may or may not work. It looks to be a similar issue for sure.
          mridgway Michael Ridgway made changes -
          Attachment DDC500Test.php [ 10560 ]
          mridgway Michael Ridgway made changes -
          Attachment DDC500Test.php [ 10560 ]
          Hide
          mridgway Michael Ridgway added a comment -

          Fixed test case. Now gives the 'Undefined index: id' error.

          Show
          mridgway Michael Ridgway added a comment - Fixed test case. Now gives the 'Undefined index: id' error.
          mridgway Michael Ridgway made changes -
          Attachment DDC500Test.php [ 10561 ]
          romanb Roman S. Borschel made changes -
          Fix Version/s 2.0-BETA1 [ 10030 ]
          romanb Roman S. Borschel made changes -
          Link This issue is referenced by DDC-497 [ DDC-497 ]
          romanb Roman S. Borschel made changes -
          Priority Minor [ 4 ] Critical [ 2 ]
          romanb Roman S. Borschel made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          romanb Roman S. Borschel added a comment -

          Reproduced successfully and working on it.

          Show
          romanb Roman S. Borschel added a comment - Reproduced successfully and working on it.
          Show
          romanb Roman S. Borschel added a comment - Fixed in http://github.com/doctrine/doctrine2/commit/760ea34a0cc3cae4e3caea17e8aab6ceb74ecace
          romanb Roman S. Borschel made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira [ 11190 ] jira-feedback [ 15610 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira-feedback [ 15610 ] jira-feedback2 [ 17474 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 17474 ] jira-feedback3 [ 19731 ]

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={expand=changesets[0:20].revisions[0:29],reviews, query=DDC-500}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

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

              Dates

              • Created:
                Updated:
                Resolved: