Skip to content

Commit aba8d74

Browse files
committed
Deprecate usage of @joincolumn on the inverse side of one-to-one associations
Following up on #10652: #### Current situation The implementation of `\Doctrine\ORM\Mapping\ClassMetadataInfo::_validateAndCompleteOneToOneMapping` will consider a field with a one-to-one association to be the owning side also when it configures `@JoinColumn` settings. #### Suggested change For a one to one association, a field should be the inverse side when it uses the `mappedBy` attribute, and be the owning side otherwise. The `JoinColumn` may be configured on the owning side only. This PR adds a deprecation notice when `@JoinColumn` is used on the side of a one-to-one association where `mappedBy` occurs. In 3.0, this will throw a `MappingException`.
1 parent a056552 commit aba8d74

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

UPGRADE.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Upgrade to 2.15
22

3+
## Deprecated configuring `JoinColumn` on the inverse side of one-to-one associations
4+
5+
For one-to-one associations, the side using the `mappedBy` attribute is the inverse side.
6+
The owning side is the entity with the table containing the foreign key. Using `JoinColumn`
7+
configuration on the _inverse_ side now triggers a deprecation notice and will be an error
8+
in 3.0.
9+
310
## Deprecated overriding fields or associations not declared in mapped superclasses
411

512
As stated in the documentation, fields and associations may only be overridden when being inherited

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

+8
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,14 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping)
18641864
{
18651865
$mapping = $this->_validateAndCompleteAssociationMapping($mapping);
18661866

1867+
if (isset($mapping['joinColumns']) && $mapping['joinColumns'] && ! $mapping['isOwningSide']) {
1868+
Deprecation::trigger(
1869+
'doctrine/orm',
1870+
'https://github.com/doctrine/orm/pull/10654',
1871+
'JoinColumn configuration is not allowed on the inverse side of one-to-one associations, and will throw a MappingException in Doctrine ORM 3.0'
1872+
);
1873+
}
1874+
18671875
if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
18681876
$mapping['isOwningSide'] = true;
18691877
}

0 commit comments

Comments
 (0)