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

        Nils Adermann created issue -
        Nils Adermann made changes -
        Field Original Value New Value
        Description Consider this example:
        {code}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{code}
        With data:
        {code}
        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]}]
        {code}

        The result currently is:
        {code}
        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
            )
        )
        {/code}

        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:
        {code}
        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)
            )
        )
        {/code}

        The difference is that numPhones for each row now contains an array of the
        scalar values matching the corresponding users.
        Consider this example:
        {code}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{code}
        With data:
        {code}
        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]}]
        {code}

        The result currently is:
        {code}
        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
            )
        )
        {/code}

        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:
        {code}
        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)
            )
        )
        {code}

        The difference is that numPhones for each row now contains an array of the
        scalar values matching the corresponding users.
        Nils Adermann made changes -
        Description Consider this example:
        {code}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{code}
        With data:
        {code}
        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]}]
        {code}

        The result currently is:
        {code}
        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
            )
        )
        {/code}

        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:
        {code}
        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)
            )
        )
        {code}

        The difference is that numPhones for each row now contains an array of the
        scalar values matching the corresponding users.
        Consider this example:
        {code}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{code}
        With data:
        {code}
        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]}]
        {code}

        The result currently is:
        {code}
        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
            )
        )
        {code}

        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:
        {code}
        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)
            )
        )
        {code}

        The difference is that numPhones for each row now contains an array of the
        scalar values matching the corresponding users.
        Benjamin Eberlei made changes -
        Workflow jira [ 12991 ] jira-feedback [ 13963 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13963 ] jira-feedback2 [ 15827 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15827 ] jira-feedback3 [ 18083 ]

          People

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

            Dates

            • Created:
              Updated: