Skip to content

Commit 7b5faff

Browse files
authored
Merge pull request #10654 from mpdude/join-column-does-not-make-it-own
Deprecate usage of `@JoinColumn` on the inverse side of one-to-one associations
2 parents a056552 + aba8d74 commit 7b5faff

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)