Skip to content

Commit

Permalink
Merge pull request #10654 from mpdude/join-column-does-not-make-it-own
Browse files Browse the repository at this point in the history
Deprecate usage of `@JoinColumn` on the inverse side of one-to-one associations
  • Loading branch information
greg0ire authored Apr 26, 2023
2 parents a056552 + aba8d74 commit 7b5faff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Upgrade to 2.15

## Deprecated configuring `JoinColumn` on the inverse side of one-to-one associations

For one-to-one associations, the side using the `mappedBy` attribute is the inverse side.
The owning side is the entity with the table containing the foreign key. Using `JoinColumn`
configuration on the _inverse_ side now triggers a deprecation notice and will be an error
in 3.0.

## Deprecated overriding fields or associations not declared in mapped superclasses

As stated in the documentation, fields and associations may only be overridden when being inherited
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,14 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping)
{
$mapping = $this->_validateAndCompleteAssociationMapping($mapping);

if (isset($mapping['joinColumns']) && $mapping['joinColumns'] && ! $mapping['isOwningSide']) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10654',
'JoinColumn configuration is not allowed on the inverse side of one-to-one associations, and will throw a MappingException in Doctrine ORM 3.0'
);
}

if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
$mapping['isOwningSide'] = true;
}
Expand Down

0 comments on commit 7b5faff

Please sign in to comment.