mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Failing inverse One-to-One relationship using a custom data type #5159
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 @alexb-uk on GitHub (Jun 20, 2016).
Originally assigned to: @lcobucci on GitHub.
Issue
The BasicEntityPersister, possibly loadOneToOneEntity() method, does not handle One-to-One relationships on the inverse side when using a custom data type.
I've stepped through the code and can see that getTypes() method is failing to find a mapping due to the SQL field name being passed in rather than the class field. E.g. from the example below its "t0.shipping_id" but I think should be "shipping". Unfortunately my understanding of the internals of Doctrine is not enough to spot the exact cause / place to fix.
Steps to reproduce
Create two classes with a one-to-one relationship using a custom data type. I used the Ramsey UUID library and Doctrine integration.
Create DQL that filters based on the inverse side and not that hydrated object returned has NULL for the relationship.
Filtering on owning side or using entityManager-find('Shipping', $id) both work correctly.
If I can give any more information or perform any tests please don't hesistate to ask.
Versions
doctrine/common v2.5.3
doctrine/dbal v2.5.4
doctrine/doctrine-module 1.0.0
doctrine/doctrine-orm-module 0.10.0
doctrine/orm v2.5.4
ramsey/uuid-doctrine 1.2.0
YAML mappings
Working Example - Owning Side
SQL Generated
Broken Example - Inverse side
SQL Generated
Note: shipping_id is using the string representation not database value.
Thanks a lot for any help / advice or even a suggested bug fix.
Alex
@liamjay commented on GitHub (Aug 16, 2016):
Can someone please have a look into this bug. I would look into myself but will probably end up breaking stuff!!!
@necsord commented on GitHub (Feb 3, 2017):
I came across this bug and while debugging I found following line:
BasicEntityPersister.php#L786
Keys of
$identifierarray are being used inBasicEntityPersister::getTypesbut since the keys are in the form oftable_alias.column_namee.g.t0_.user_idit can't find the appropriate type.After changing previously mentioned line to:
Which results in keys being in the form of mapped class field name and in
BasicEntityPersister::getTypesit gets mapped correctly using target classassociationMappings.I did not test this heavily but it works for the case with which I had trouble but as I never worked with doctrine source code it would be best if someone took a look at it. I'll try creating pull request for this over the weekend but if someone wants to do it sooner feel free.
@lcobucci commented on GitHub (Apr 30, 2017):
@alexb-uk can you please check if that is fixed on
mastersince #6274 got merged?@Ma27 commented on GitHub (Jan 23, 2019):
I'm afraid this has implications on bidirectional one-to-one relations with multiple JoinColumns: #7579