Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined Property error in ObjectHydrator when using JOIN WITH #6362

Closed
SirWaddles opened this issue Mar 27, 2017 · 2 comments
Closed

Undefined Property error in ObjectHydrator when using JOIN WITH #6362

SirWaddles opened this issue Mar 27, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@SirWaddles
Copy link
Contributor

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.

@lcobucci
Copy link
Member

lcobucci commented Mar 27, 2017

This is a known limitation of the ORM when working with class table inheritance and might not be properly documented.

@SirWaddles would be nice if you could reproduce and implement a good (tested) solution for this on a PR.

@lcobucci
Copy link
Member

lcobucci commented May 2, 2017

Fixed by #6367

@lcobucci lcobucci closed this as completed May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants