Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1357

Queries with multiple joins resulting in multiple scalar results for each top level entity only retain one scalar value for each entity

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Consider this example:

      select g.id, u.id, u.status, count(p.phonenumber) numPhones from Group
           * g join g.user u join u.phonenumbers p group by g.id, u.status, u.id

      With data:

      phonenumbers:
          [1, 2, 3, 4, 5, 6]
      users:
          [{id: 1, status: developer, phonenumbers: [1, 2]},
           {id: 2, status: developer, phonenumbers: [3]},
           {id: 3, status: developer, phonenumbers: [4, 5, 6]}]
      groups:
          [{id: 1, users: [1, 2]]},
           {id:2, users: [3]}]
      

      The result currently is:

      array(
          array(
              0 => object(CmsGroup) {
                  'id' => 1,
                  'users' => Collection(
                      object(CmsUser) { 'id' => 1 },
                      object(CmsUser) { 'id' => 2 }
                  )
               },
              'numPhones' => 1
          ),
          array(
              0 => object(CmsGroup) {
                  'id' => 2,
                  'users' => Collection(
                      object(CmsUser) { 'id' => 3 }
                  )
              },
              'numPhones' => 3
          )
      )
      

      Note that the first entry contains only one value numPhones => 1, even though there are two users associated with that group. One of whom has 2 phone numbers and the other has 1.

      The result I would expect is:

      array(
          array(
              0 => object(CmsGroup) {
                  'id' => 1,
                  'users' => Collection(
                      object(CmsUser) { 'id' => 1 },
                      object(CmsUser) { 'id' => 2 }
                  )
               },
              'numPhones' => array(2, 1)
          ),
          array(
              0 => object(CmsGroup) {
                  'id' => 2,
                  'users' => Collection(
                      object(CmsUser) { 'id' => 3 }
                  )
              },
              'numPhones' => array(3)
          )
      )
      

      The difference is that numPhones for each row now contains an array of the
      scalar values matching the corresponding users.

        Activity

        Hide
        Nils Adermann added a comment -
        Show
        Nils Adermann added a comment - You can find a test case for the correct result here: https://github.com/naderman/doctrine2/commit/a1ca3d9847cbc514fc951fb0b221b26fe03a6619

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Nils Adermann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: