Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
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.
You can find a test case for the correct result here: https://github.com/naderman/doctrine2/commit/a1ca3d9847cbc514fc951fb0b221b26fe03a6619