Bidirectional one-to-one relations with multiple join columns break in DQL queries #6162

Open
opened 2026-01-22 15:28:01 +01:00 by admin · 0 comments
Owner

Originally created by @Ma27 on GitHub (Jan 23, 2019).

Bug Report

Q A
BC Break yes
Version 2.6.3 (introduced in 2.6.0)

Summary

DQL queries including bidirectional one-to-one relations break with an exception as BasicEntityPersister#loadOneToOne assumes that such relations consist of a single join column since a360da5a7e as ClassMetadataInfo#getFieldForColumn breaks if an association mapping has more than one column.

Current behavior

Queries as shown in my failing testcase fail with the following exception on 2.6:

Doctrine\ORM\Mapping\MappingException: Cannot find a field on 'Doctrine\Tests\Functional\OneToOneReference' that is mapped to column 'objectId'. Either the field does not exist or an association exists but it has multiple join columns.

/home/ma27/Projects/orm/lib/Doctrine/ORM/Mapping/MappingException.php:621
/home/ma27/Projects/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:2961
/home/ma27/Projects/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:805
/home/ma27/Projects/orm/lib/Doctrine/ORM/UnitOfWork.php:2708
/home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:271
/home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:492
/home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:162
/home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:152
/home/ma27/Projects/orm/lib/Doctrine/ORM/AbstractQuery.php:976
/home/ma27/Projects/orm/lib/Doctrine/ORM/AbstractQuery.php:922
/home/ma27/Projects/orm/lib/Doctrine/ORM/AbstractQuery.php:726
/home/ma27/Projects/orm/tests/Doctrine/Tests/ORM/Functional/OneToOneWithMultipleJoinColumnsTest.php:43

How to reproduce

I created a failing testcase in my fork which passes on 2.5, but fails on 2.6.

I didn't test it on master as it misses the method Doctrine\ORM\Persisters\Entity\BasicEntityPersister#loadOneToOneEntity. I assume that 3.0/master is too far diverged from 2.6, so a reproduction on master will be way harder.

Expected behavior

That the $qb->getQuery()->getResult() (see my example) resolves to an entity and doesn't break with an exception.

Originally created by @Ma27 on GitHub (Jan 23, 2019). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 2.6.3 (introduced in 2.6.0) #### Summary DQL queries including bidirectional one-to-one relations break with an exception as `BasicEntityPersister#loadOneToOne` assumes that such relations consist of a single join column since a360da5a7e5463f6c12b0922f6063e1cf32dde6d as `ClassMetadataInfo#getFieldForColumn` breaks if an association mapping has more than one column. #### Current behavior Queries as shown in my failing testcase fail with the following exception on 2.6: ``` Doctrine\ORM\Mapping\MappingException: Cannot find a field on 'Doctrine\Tests\Functional\OneToOneReference' that is mapped to column 'objectId'. Either the field does not exist or an association exists but it has multiple join columns. /home/ma27/Projects/orm/lib/Doctrine/ORM/Mapping/MappingException.php:621 /home/ma27/Projects/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:2961 /home/ma27/Projects/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:805 /home/ma27/Projects/orm/lib/Doctrine/ORM/UnitOfWork.php:2708 /home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:271 /home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:492 /home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:162 /home/ma27/Projects/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:152 /home/ma27/Projects/orm/lib/Doctrine/ORM/AbstractQuery.php:976 /home/ma27/Projects/orm/lib/Doctrine/ORM/AbstractQuery.php:922 /home/ma27/Projects/orm/lib/Doctrine/ORM/AbstractQuery.php:726 /home/ma27/Projects/orm/tests/Doctrine/Tests/ORM/Functional/OneToOneWithMultipleJoinColumnsTest.php:43 ``` #### How to reproduce I created a [failing testcase](https://github.com/Ma27/orm/commit/5d5b576cc49f0ec1dbb6ecad3cf4d7d1002f1eb5) in my fork which passes on `2.5`, but fails on `2.6`. I didn't test it on master as it misses the method `Doctrine\ORM\Persisters\Entity\BasicEntityPersister#loadOneToOneEntity`. I assume that 3.0/master is too far diverged from 2.6, so a reproduction on master will be way harder. #### Expected behavior That the `$qb->getQuery()->getResult()` (see my example) resolves to an entity and doesn't break with an exception.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6162