Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate usage of @JoinColumn on the inverse side of one-to-one associations #10654

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Apr 25, 2023

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.

@mpdude mpdude changed the title Throw an exception when the inverse side configures the join column(s) Deprecate usage of @JoinColumn on the inverse side of one-to-one associations Apr 25, 2023
@mpdude mpdude force-pushed the join-column-does-not-make-it-own branch from c870020 to 63ff848 Compare April 25, 2023 09:50
@mpdude
Copy link
Contributor Author

mpdude commented Apr 25, 2023

Tests will pass with the changes from #10652.

@mpdude mpdude marked this pull request as ready for review April 25, 2023 10:45
@mpdude mpdude force-pushed the join-column-does-not-make-it-own branch 2 times, most recently from d7bfd38 to 917a656 Compare April 25, 2023 12:00
@derrabus
Copy link
Member

Something went wrong when rebasing this PR, apparently. The diff contains changes that have already been merged to 2.15.x.

@mpdude mpdude force-pushed the join-column-does-not-make-it-own branch from 917a656 to 9b44181 Compare April 25, 2023 12:39
@mpdude mpdude force-pushed the join-column-does-not-make-it-own branch 2 times, most recently from 14f5b69 to 98177e4 Compare April 25, 2023 13:27
…ciations

Following up on doctrine#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`.
@mpdude mpdude force-pushed the join-column-does-not-make-it-own branch from 98177e4 to aba8d74 Compare April 25, 2023 13:29
@greg0ire greg0ire added this to the 2.15.0 milestone Apr 26, 2023
@greg0ire greg0ire merged commit 7b5faff into doctrine:2.15.x Apr 26, 2023
@greg0ire
Copy link
Member

Thanks @mpdude !

@mpdude mpdude deleted the join-column-does-not-make-it-own branch April 26, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants