Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1452

ObjectHydrator bug: hydration of entity with self (cyclic) relation through ref entity

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1, 2.1.1, 2.1.2
    • Fix Version/s: 2.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      ObjectHydrator has bug in hydrate entities with relation to entity of this same class throught reference entity. Example Model:

      EntityA

      • id
      • title (string)
      • entitiesB (annotation: @ORM\OneToMany(targetEntity="EntityB", mappedBy="entityAFrom"))

      EntityB

      • id
      • entityAFrom (annotation: @ORM\ManyToOne(targetEntity="EntityA", inversedBy="entitiesB"))
      • entityATo (annotation: @ORM\ManyToOne(targetEntity="EntityA"))
      • type (string)

      Scenario:

      Execution of dql query 'SELECT a, b, ba FROM EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba' with max results set to "1" and data in database:

      EntityATable:
      id | title
      1 | a
      2 | b

      EntityBTable:
      id | entityAFromId | entityAToId | type
      1 | 1 | 2 | type

      Resume:

      I expected collection of EntityA object (size=1 becouse I set max results to 1) with hydrated entitiesB collection (size=1 becouse in db is only 1 record) and hydrated entityTo object. entitiesB property of entityTo object should be empty PersistCollection (ready to lazy load) but is null...

      I can provide TestCase for this issue.

      1. DDC1452Test.php
        2 kB
        Piotr Śliwa
      2. DDC1452Test.php
        2 kB
        Benjamin Eberlei

        Activity

        Piotr Śliwa created issue -
        Piotr Śliwa made changes -
        Field Original Value New Value
        Component/s ORM [ 10012 ]
        Component/s Mapping Drivers [ 10044 ]
        Piotr Śliwa made changes -
        Description ObjectHydrator has bug in hydrate entities with relation to entity of this same class throught reference entity. Example Model:

        EntityA
        - id
        - title (string)
        - entitiesB (annotation: @ORM\OneToMany(targetEntity="EntityB", mappedBy="entityAFrom"))

        EntityB
        - id
        - entityAFrom (annotation: @ORM\ManyToOne(targetEntity="EntityA", inversedBy="entitiesB"))
        - entityATo (annotation: @ORM\ManyToOne(targetEntity="EntityA"))
        - type (string)

        Scenario:

        Execution dql query 'SELECT a, b, ba FROM EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba' with max results set to "1" and data in database:

        EntityATable:
        id | title
        1 | a
        2 | b

        EntityBTable:
        id | entityAFromId | entityAToId | type
        1 | 1 | 2 | type

        Resume:

        I expected collection of EntityA object (size=1 becouse I set max results to 1) with hydrated entitiesB collection (size=1 becouse in db is only 1 record) and hydrated entityTo object. entitiesB property of entityTo object should be empty PersistCollection (ready to lazy load) but is null...

        I can provide TestCase for this issue.
        ObjectHydrator has bug in hydrate entities with relation to entity of this same class throught reference entity. Example Model:

        EntityA
        - id
        - title (string)
        - entitiesB (annotation: @ORM\OneToMany(targetEntity="EntityB", mappedBy="entityAFrom"))

        EntityB
        - id
        - entityAFrom (annotation: @ORM\ManyToOne(targetEntity="EntityA", inversedBy="entitiesB"))
        - entityATo (annotation: @ORM\ManyToOne(targetEntity="EntityA"))
        - type (string)

        Scenario:

        Execution of dql query 'SELECT a, b, ba FROM EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba' with max results set to "1" and data in database:

        EntityATable:
        id | title
        1 | a
        2 | b

        EntityBTable:
        id | entityAFromId | entityAToId | type
        1 | 1 | 2 | type

        Resume:

        I expected collection of EntityA object (size=1 becouse I set max results to 1) with hydrated entitiesB collection (size=1 becouse in db is only 1 record) and hydrated entityTo object. entitiesB property of entityTo object should be empty PersistCollection (ready to lazy load) but is null...

        I can provide TestCase for this issue.
        Benjamin Eberlei made changes -
        Priority Major [ 3 ] Critical [ 2 ]
        Benjamin Eberlei made changes -
        Attachment DDC1452Test.php [ 11091 ]
        Piotr Śliwa made changes -
        Attachment DDC1452Test.php [ 11092 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Benjamin Eberlei made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.2-DEV [ 10157 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13124 ] jira-feedback [ 15083 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15083 ] jira-feedback2 [ 16947 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16947 ] jira-feedback3 [ 19200 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Piotr Śliwa
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: