I’ve got two entities, with a “logical” 1:1 relation which is, however, not configured (they don’t know they’re related to each other).
I can’t just configure this relation because there’s a lot of older code depending on this situation (see below for further explanation).
Now, I’m trying to resolve this relation manually using a simple SELECT query with a LEFT JOIN clause:
SELECT E1 as my_cool_entity_1, E2 as my_cool_entity_2
FROM Namespace\Of\Entity1 E1
LEFT JOIN Namespace\Of\Entity2 E2
WITH E2.someColumn = E1.someOtherColumn
In my case, there is exactly one row matching E1 and one row matching the join on E2. Somehow, I’ve used Doctrine in that way earlier, but I can’t remember where and how. The result expected is an array like this:
[0 => [
"my_cool_entity_1" => (Instance of E1),
"my_cool_entity_2" => (Instance of E2)
]]
Instead, the array looks like this:
[0 => [
"my_cool_entity_1" => (Instance of E1)
],
1 => [
"my_cool_entity_2" => (Instance of E2)
]]
How is it possible to make Doctrine hydrate the array as I’m expecting it? Thanks in advance!
Note: I wrote that I can’t define the relation between these 2 entities. That’s because, if a relation is defined, Doctrine requires you to assign the instance of E2 to E1 when saving E1 — in my older code, however, I’m only assigning the related ID. Thus, Doctrine would ignore E2 at all and cause constraints errors.
without a definition of the relation doctrine can not know that it’s a oneToOne relation so the result will always be a collection. you need to write your own hydrator to achieve this.