Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1652

ArrayHydrator with composite primary key

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Hi.

      Problem with ArrayHydrator and composite primary key.

      Given the following data (PRIMARY KEY (`ancestor_id`,`descendant_id`))

      ancestor_id descendant_id depth
      1 1 0
      1 2 1
      $query = $em->createQuery("SELECT c,d FROM ResourceClosure c JOIN c.descendant d WHERE c.ancestor = 1");
      
      echo 'ObjectHydrator result count = '.count($query->getResult()).PHP_EOL;
      echo 'ArrayHydrator result count = '.count($query->getArrayResult()).PHP_EOL;
      
      Output
      ObjectHydrator result count = 2 
      ArrayHydrator result count = 1 
      

      Expected both counts are equals 2.
      In case getArrayResult() in result only first record hydrated, second record are ommited

      Below examples model and insertion in db

      ResourceClosure
      /**
       * @Entity
       */
      class ResourceClosure
      {
          /**
           * @Id
           * @ManyToOne(targetEntity="Resource")
           * @JoinColumn(name="ancestor_id", referencedColumnName="id")
           *
           */
          private $ancestor;
      
          /**
           * @Id
           * @ManyToOne(targetEntity="Resource")
           * @JoinColumn(name="descendant_id", referencedColumnName="id")
           * @var Resource
           */
          private $descendant;
      
          /**
           * @Column(name="depth", type="integer")
           * @var integer
           */
          private $depth;
      }
      
      Insertion
      $resource1 = new Entity\Resource('resource1');
      $em->persist($resource1);
      
      $resource2 = new Entity\Resource('resource2');
      $em->persist($resource2);
      
      $em->flush();
      
      $closure1 = new Entity\ResourceClosure();
      $closure1->setAncestor($resource1)
                      ->setDescendant($resource1)
                      ->setDepth(0);
      
      $em->persist($closure1);
      
      
      $closure2= new Entity\ResourceClosure();
      $closure2->setAncestor($resource1)
                      ->setDescendant($resource2)
                      ->setDepth(1);
      
      $em->persist($closure2);
      
      
      $em->flush();
      

      P.S.
      Its work like expected in case entity ResourceClosure has simple primary key.

        Activity

        Gandzy Ghennady created issue -
        Gandzy Ghennady made changes -
        Field Original Value New Value
        Description Hi.

        Problem with ArrayHydrator and composite primary key.

        {code}
        $query = $em->createQuery("SELECT c,d FROM ResourceClosure c JOIN c.descendant d WHERE c.ancestor = 1");

        echo 'ObjectHydrator result count = '.count($query->getResult()).PHP_EOL;
        echo 'ArrayHydrator result count = '.count($query->getArrayResult()).PHP_EOL;
        {code}

        {code:title=Output}
        ObjectHydrator result count = 2
        ArrayHydrator result count = 1
        {code}
        Expected both counts are equals 2.
        In case getArrayResult() in result only first record hydrated, second record are ommited


        Below examples model and insertion in db
        {code:title=ResourceClosure}
        /**
         * @Entity
         */
        class ResourceClosure
        {
            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="ancestor_id", referencedColumnName="id")
             *
             */
            private $ancestor;

            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="descendant_id", referencedColumnName="id")
             * @var Resource
             */
            private $descendant;

            /**
             * @Column(name="depth", type="integer")
             * @var integer
             */
            private $depth;
        }
        {code}

        {code:title=Insertion}
        $resource1 = new Entity\Resource('resource1');
        $em->persist($resource1);

        $resource2 = new Entity\Resource('resource2');
        $em->persist($resource2);

        $em->flush();

        $closure1 = new Entity\ResourceClosure();
        $closure1->setAncestor($resource1)
                        ->setDescendant($resource1)
                        ->setDepth(0);

        $em->persist($closure1);


        $closure2= new Entity\ResourceClosure();
        $closure2->setAncestor($resource1)
                        ->setDescendant($resource2)
                        ->setDepth(1);

        $em->persist($closure2);


        $em->flush();
        {code}

        P.S.
        Its work like expected in case entity ResourceClosure has simple primary key.
        Hi.

        Problem with ArrayHydrator and composite primary key.

        Given the following data
        ||ancestor_id||descendant_id||depth||
        |1|1|0|
        |1|2|1|

        {code}
        $query = $em->createQuery("SELECT c,d FROM ResourceClosure c JOIN c.descendant d WHERE c.ancestor = 1");

        echo 'ObjectHydrator result count = '.count($query->getResult()).PHP_EOL;
        echo 'ArrayHydrator result count = '.count($query->getArrayResult()).PHP_EOL;
        {code}

        {code:title=Output}
        ObjectHydrator result count = 2
        ArrayHydrator result count = 1
        {code}
        Expected both counts are equals 2.
        In case getArrayResult() in result only first record hydrated, second record are ommited


        Below examples model and insertion in db
        {code:title=ResourceClosure}
        /**
         * @Entity
         */
        class ResourceClosure
        {
            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="ancestor_id", referencedColumnName="id")
             *
             */
            private $ancestor;

            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="descendant_id", referencedColumnName="id")
             * @var Resource
             */
            private $descendant;

            /**
             * @Column(name="depth", type="integer")
             * @var integer
             */
            private $depth;
        }
        {code}

        {code:title=Insertion}
        $resource1 = new Entity\Resource('resource1');
        $em->persist($resource1);

        $resource2 = new Entity\Resource('resource2');
        $em->persist($resource2);

        $em->flush();

        $closure1 = new Entity\ResourceClosure();
        $closure1->setAncestor($resource1)
                        ->setDescendant($resource1)
                        ->setDepth(0);

        $em->persist($closure1);


        $closure2= new Entity\ResourceClosure();
        $closure2->setAncestor($resource1)
                        ->setDescendant($resource2)
                        ->setDepth(1);

        $em->persist($closure2);


        $em->flush();
        {code}

        P.S.
        Its work like expected in case entity ResourceClosure has simple primary key.
        Gandzy Ghennady made changes -
        Description Hi.

        Problem with ArrayHydrator and composite primary key.

        Given the following data
        ||ancestor_id||descendant_id||depth||
        |1|1|0|
        |1|2|1|

        {code}
        $query = $em->createQuery("SELECT c,d FROM ResourceClosure c JOIN c.descendant d WHERE c.ancestor = 1");

        echo 'ObjectHydrator result count = '.count($query->getResult()).PHP_EOL;
        echo 'ArrayHydrator result count = '.count($query->getArrayResult()).PHP_EOL;
        {code}

        {code:title=Output}
        ObjectHydrator result count = 2
        ArrayHydrator result count = 1
        {code}
        Expected both counts are equals 2.
        In case getArrayResult() in result only first record hydrated, second record are ommited


        Below examples model and insertion in db
        {code:title=ResourceClosure}
        /**
         * @Entity
         */
        class ResourceClosure
        {
            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="ancestor_id", referencedColumnName="id")
             *
             */
            private $ancestor;

            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="descendant_id", referencedColumnName="id")
             * @var Resource
             */
            private $descendant;

            /**
             * @Column(name="depth", type="integer")
             * @var integer
             */
            private $depth;
        }
        {code}

        {code:title=Insertion}
        $resource1 = new Entity\Resource('resource1');
        $em->persist($resource1);

        $resource2 = new Entity\Resource('resource2');
        $em->persist($resource2);

        $em->flush();

        $closure1 = new Entity\ResourceClosure();
        $closure1->setAncestor($resource1)
                        ->setDescendant($resource1)
                        ->setDepth(0);

        $em->persist($closure1);


        $closure2= new Entity\ResourceClosure();
        $closure2->setAncestor($resource1)
                        ->setDescendant($resource2)
                        ->setDepth(1);

        $em->persist($closure2);


        $em->flush();
        {code}

        P.S.
        Its work like expected in case entity ResourceClosure has simple primary key.
        Hi.

        Problem with ArrayHydrator and composite primary key.

        Given the following data (PRIMARY KEY (`ancestor_id`,`descendant_id`))
        ||ancestor_id||descendant_id||depth||
        |1|1|0|
        |1|2|1|



        {code}
        $query = $em->createQuery("SELECT c,d FROM ResourceClosure c JOIN c.descendant d WHERE c.ancestor = 1");

        echo 'ObjectHydrator result count = '.count($query->getResult()).PHP_EOL;
        echo 'ArrayHydrator result count = '.count($query->getArrayResult()).PHP_EOL;
        {code}

        {code:title=Output}
        ObjectHydrator result count = 2
        ArrayHydrator result count = 1
        {code}
        Expected both counts are equals 2.
        In case getArrayResult() in result only first record hydrated, second record are ommited


        Below examples model and insertion in db
        {code:title=ResourceClosure}
        /**
         * @Entity
         */
        class ResourceClosure
        {
            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="ancestor_id", referencedColumnName="id")
             *
             */
            private $ancestor;

            /**
             * @Id
             * @ManyToOne(targetEntity="Resource")
             * @JoinColumn(name="descendant_id", referencedColumnName="id")
             * @var Resource
             */
            private $descendant;

            /**
             * @Column(name="depth", type="integer")
             * @var integer
             */
            private $depth;
        }
        {code}

        {code:title=Insertion}
        $resource1 = new Entity\Resource('resource1');
        $em->persist($resource1);

        $resource2 = new Entity\Resource('resource2');
        $em->persist($resource2);

        $em->flush();

        $closure1 = new Entity\ResourceClosure();
        $closure1->setAncestor($resource1)
                        ->setDescendant($resource1)
                        ->setDepth(0);

        $em->persist($closure1);


        $closure2= new Entity\ResourceClosure();
        $closure2->setAncestor($resource1)
                        ->setDescendant($resource2)
                        ->setDepth(1);

        $em->persist($closure2);


        $em->flush();
        {code}

        P.S.
        Its work like expected in case entity ResourceClosure has simple primary key.
        Benjamin Eberlei made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Benjamin Eberlei added a comment -

        Verified

        Show
        Benjamin Eberlei added a comment - Verified
        Hide
        Benjamin Eberlei added a comment -

        @Guilherme - This is because the SQL Walker decides to $addMetaColumns => false here. Why did we add this? This skips all meta columns in Array Results, i don't get what that is good for.

        Show
        Benjamin Eberlei added a comment - @Guilherme - This is because the SQL Walker decides to $addMetaColumns => false here. Why did we add this? This skips all meta columns in Array Results, i don't get what that is good for.
        Hide
        Benjamin Eberlei added a comment -

        PR: https://github.com/doctrine/doctrine2/pull/290

        Guilherme has to verify this

        Show
        Benjamin Eberlei added a comment - PR: https://github.com/doctrine/doctrine2/pull/290 Guilherme has to verify this
        Hide
        Guilherme Blanco added a comment -
        Show
        Guilherme Blanco added a comment - Resolved with merge of https://github.com/doctrine/doctrine2/pull/290
        Guilherme Blanco made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.3 [ 10185 ]
        Resolution Fixed [ 1 ]
        Hide
        Benjamin Eberlei added a comment -

        Merged back to 2.2, will be in 2.2.1

        Show
        Benjamin Eberlei added a comment - Merged back to 2.2, will be in 2.2.1
        Benjamin Eberlei made changes -
        Fix Version/s 2.2.1 [ 10194 ]
        Fix Version/s 2.3 [ 10185 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13451 ] jira-feedback [ 15232 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15232 ] jira-feedback2 [ 17096 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17096 ] jira-feedback3 [ 19349 ]

        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={query=DDC-1652, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Gandzy Ghennady
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: