mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Composite key issue when joining #7187
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tomatov-net on GitHub (Jul 17, 2023).
Bug Report
Summary
When we join a sub entity, with a composite primary key, we get the same entity for all the primary ones.
Current behavior
I have a feeling that when doctrine builds an object from the query result, it doesn’t care about uniqueness of the sub objects and just use the same one all the parents.
How to reproduce
We have the next structure: Cart→offer→fees
One Cart belongs to one offer, each offer may have several fees.
offer_idandtypeare a composite primary key of the Fee.Cart.xml.orm
Offer.xml.orm:
Fee.xml.orm:
When we join Fee via Offer, for some reason we have the same Fee for all the Cart objects. The SQL is fine when we debug it, it’s valid, but something is wrong with mapping after running the query.
Now we have an array of 2 Cart objects after the query finished. However, the nested object
Feeis exactly the same:$result[0]→offer→fees === $result[1]→offer→fees, but in the database they are different.Expected behavior
Each nested entity should be unique and joined correctly, as it was described in the ORM file.
This problem could be solved by adding its own unique
idfield into theFeemodel, with it everything will work fine, as we've tested it many times. But for just a composite key without ownid, doctrine fails to get the correct result 🎲