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

Misleading error message for bi-dir O:O with no mappedBy #9536

Closed
kiler129 opened this issue Feb 22, 2022 · 0 comments · Fixed by #9537
Closed

Misleading error message for bi-dir O:O with no mappedBy #9536

kiler129 opened this issue Feb 22, 2022 · 0 comments · Fixed by #9537

Comments

@kiler129
Copy link
Contributor

kiler129 commented Feb 22, 2022

Bug Report

Q A
BC Break no
Version 2.11.1

Summary

Wrong validation message is displayed when an incorrect bidirectional one-to-one mapping is set up. When the owning side is configured correctly and the target side is missing the back reference the ORM suggests adding inverseBy instead of mappedBy.

I may be wrong, but adding such inversedBy creates another error in the mapping, while using mappedBy results in mapping passing the validation.

Current behavior

Mapping
-------

 [FAIL] The entity-class App\Entity\Media mapping is invalid:
 * The field App\Entity\Media#attachment is on the owning side of a bi-directional relationship, but the specified mappedBy association on the target-entity App\Entity\Attachment# does not contain the required 'inversedBy' attribute.

How to reproduce

  1. Configure two entities like so:
#[ORM\Entity]
class Media
{
    //...
    #[ORM\OneToOne(inversedBy: 'media')]
    #[ORM\JoinColumn(name: 'ZTH1', referencedColumnName: 'ZPK')]
    private Attachment $attachment;
}

#[ORM\Entity]
class Attachment
{
    #[ORM\OneToOne]
    #[ORM\JoinColumn(name: 'ZMD0', referencedColumnName: 'ZPK')]
    private ?Media $media;
  1. Run bin/console doctrine:schema:validate

Expected behavior

I believe that the message should suggest adding mappedBy and not inversedBy, as according to the docs, the owning side needs inversedBy while the target side uses mappedBy. In addition it seems like the target entity reference should contain a field which is missing (nothing after #).

With both fixed the message will look like the following:

 [FAIL] The entity-class App\Entity\Media mapping is invalid:
 * The field App\Entity\Media#attachment is on the owning side of a bi-directional relationship, but the specified mappedBy association on the target-entity App\Entity\Attachment#media does not contain the required 'mappedBy' attribute.

See PR #9537

kiler129 added a commit to kiler129/orm that referenced this issue Feb 22, 2022
Wrong validation message is displayed when an incorrect bidirectional
one-to-one mapping is set up. When the owning side is configured
correctly and the target side is missing the back reference the ORM
suggests adding inverseBy instead of mappedBy, with the field name
missing.
kiler129 added a commit to kiler129/orm that referenced this issue Feb 22, 2022
Wrong validation message is displayed when an incorrect bidirectional
bi-directional mapping is set up. When the owning side is configured
correctly and the target side is missing the back reference, the ORM
suggests adding inverseBy instead of mappedBy, with the field name
missing. This commit fixes this problem.
kiler129 added a commit to kiler129/orm that referenced this issue Feb 22, 2022
Wrong validation message is displayed when an incorrect bidirectional
bi-directional mapping is set up. When the owning side is configured
correctly and the target side is missing the back reference, the ORM
suggests adding inverseBy instead of mappedBy, with the field name
missing. This commit fixes this problem.
derrabus added a commit that referenced this issue Feb 24, 2022
derrabus added a commit to derrabus/orm that referenced this issue Feb 25, 2022
* 2.12.x:
  Document QueryComponent array shape (doctrine#9527)
  Improve templating
  Un-deprecate the current proxy mechanism (doctrine#9532)
  Remove unused methods
  Fix bug-doctrine#9536
derrabus added a commit to derrabus/orm that referenced this issue Feb 25, 2022
* 2.12.x:
  Document QueryComponent array shape (doctrine#9527)
  Improve templating
  Un-deprecate the current proxy mechanism (doctrine#9532)
  Remove unused methods
  Fix bug-doctrine#9536
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant