I have 2 entities with a one-to-many relationship. I need to select the name from both entity 1 and entity 2
$qb
->select(['f.name1', 'c.name2'])
->from('BundleOne:EntityOne', 'c')
->innerJoin('c.EntityTwo', 'f');
return $qb->getQuery()->getArrayResult();
With the above query, I get the following results:
1 => array:2 [
"name1" => "xyz"
"name2" => "n1"
]
2 => array:2 [
"name1" => "xyz"
"name2" => "n2"
]
3 => array:2 [
"name1" => "abc"
"name2" => "n3"
]
4 => array:2 [
"name1" => "abc"
"name2" => "n4"
]
As you can notice, since this is a one-to-many relationship, a name1
can have several name2
associated with it and instead of the above, I want to return the result as follows:
"xyz" => array:2 ["n1", "n2"]
"abc" => array:2 ["n3", "n4"]
that is the name1
as the key of the array that contains all name2
Is that possible?