You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a pretty strange issue that I can't quite work out, I have a fix but it's affecting code from 8yrs ago which seems pretty stable.
I have a DQL query resembling
SELECT base, fruits, apples, data
FROM AppBundle\Base base
LEFT JOIN base.fruits fruits
LEFT JOIN AppBundle\Apple apples WITH fruits.id = apples.id
LEFT JOIN apples.data data
where a Base can have many Fruits of multiple types. The error I get when trying to run this query is just Undefined property on AppBundle\Base::$data
For some reason, the ObjectHydrator is trying to add the values retrieved from the database to the wrong entity. After doing some debugging, I found something a little odd in ObjectHydrator.php
// Get a reference to the parent object to which the joined element belongs.if ($this->_rsm->isMixed && isset($this->rootAliases[$parentAlias])) {
$first = reset($this->resultPointers);
$parentObject = $first[key($first)];
It appears that it can only ever get a reference to the first object that there is a root alias to. After changing the second line to $first = $this->resultPointers[$parentAlias]; in a debug build, my problem is solved and although I didn't run through the unit tests (will do if it's a PR, but it seems more like I'm doing something wrong here) my application elsewhere works fine.
I realise there is a limitation when it comes to downcasting in Doctrine (which is what I am trying to do) but it seems like this issue would have broader implications.
The text was updated successfully, but these errors were encountered:
I have a pretty strange issue that I can't quite work out, I have a fix but it's affecting code from 8yrs ago which seems pretty stable.
I have a DQL query resembling
where a Base can have many Fruits of multiple types. The error I get when trying to run this query is just
Undefined property on AppBundle\Base::$data
For some reason, the ObjectHydrator is trying to add the values retrieved from the database to the wrong entity. After doing some debugging, I found something a little odd in ObjectHydrator.php
It appears that it can only ever get a reference to the first object that there is a root alias to. After changing the second line to
$first = $this->resultPointers[$parentAlias];
in a debug build, my problem is solved and although I didn't run through the unit tests (will do if it's a PR, but it seems more like I'm doing something wrong here) my application elsewhere works fine.I realise there is a limitation when it comes to downcasting in Doctrine (which is what I am trying to do) but it seems like this issue would have broader implications.
The text was updated successfully, but these errors were encountered: