-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
DDC-1960: mapping joins in native queries breaks if select columns are starting with columns from joined table #2633
Comments
Comment created by frederes: Hello, Has same issue with using DQL /createQuery() ! Try all the day to find where was my mistake but seems to be a CRITICAL bug ! Doctrine version used : 2.3.1-DEV
$query = $this->getEntityManager()->createQuery("
SELECT cc, oc
FROM category cc
JOIN cc.offer_category oc
WHERE cc.catalog = :catalog_id
ORDER BY oc.name ASC
")
->setParameter(":catalog_id", $catalog_id)
;
Problem is that the order of the Aliases (cc, oc) is not considered on building SQL . $rowData = $this->gatherRowData($row, $cache, $id, $nonemptyComponents); returns Array [oc] => Array As "oc" is a mapping, on the first loop the $parentAlias is not yet known and so : using a workaround on ObjectHydrator::hydrateRowData like this : make it work... Sorry for my dirty explanation... |
Comment created by sustmi: Here is a failing test for this issue: Release v2.5.0 is still affected. I think there is a problem with ObjectHydrator::$resultPointers array. Side note: This error occurs even with pure DQL queries (without NativeQueries and custom ResultSetMappings). |
Comment created by sustmi: Another simpler test case: sustmi@42a4da6 Also, I think this issue is a duplicate of http://www.doctrine-project.org/jira/browse/[DDC-2649](http://www.doctrine-project.org/jira/browse/DDC-2649) . |
I made a hotfix for this issue here: sustmi@de83b79 |
Any news? This just cost me a few hours of debugging, googling and swearing when my heavily optimized native query suddenly started lazy-loading hundreds of objects one by one. |
I've just found old issues that are relevant to this one: #5249, #5443, #5454 . These issues try to solve the problem that hydrators depend on the order of identifiers in It is strange because I remember the problem to happen even when using DQL (this code-path should be fixed). Sadly, I cannot remember the DQL code that would reproduce the issue. Maybe the query mentioned in #2633 (comment) reproduces the issue even in DQL. |
This test https://gist.github.com/doctrinebot/044a2dc627a11e5c3a9e#file-10846_ddc736test-php is relevant but it does not test hydrating multiple rows. |
Hi, |
Hi, we found some way by creating own package that is already on packagist. |
@boris-brtan which package? |
Items in $rowData['data'] in ArrayHydrator is now sorted by level obtained from ResultSetMapping::$parentAliasMap
Items in $rowData['data'] in ArrayHydrator is now sorted by level obtained from ResultSetMapping::$parentAliasMap
Co-authored-by: Alexander M. Turek <me@derrabus.de>
Jira issue originally created by user dready:
Using a simple Testcase like in http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/native-sql.html there are two Tables:
*) users:
*) address:
address_id is a foreign key to address;
Now i created the Entities and setup a native query using ResultSetMappingBuilder:
This returns the Entities correctly:
BUT if you change the order of the select columns starting with ones from address you get borked Data:
This happens because the function Doctrine\ORM\Internal\Hydration\AbstractHydrator::_gatherRowData does not consider the Mapping i set up. Instead it just add the columns as they get starting with address ones.
Doctrine\ORM\Internal\Hydration\ObjectHydrator::_hydrateRow then knows the Mapping and ignores the first Address as there is no User to map on, cycling to the next row will then add the address of the second row to the user from the first one.
There are multiple ways to fix this. One would be to consider the mapping in *gatherRowData, the second to rewrite the *hydrateRow generating the Entities first and then the mapping in a second foreach loop.
This bugger had me for 2 days until i finally figured it out.
thanks
The text was updated successfully, but these errors were encountered: