DDC-193: Remove ClassMetadataInfo#inverseMappings #239

Closed
opened 2026-01-22 12:31:58 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 6, 2009).

Jira issue originally created by user romanb:

The ClassMetadataInfo#inverseMappings attribute is an unnecessary complication.

The problem comes down to: "Given an association $assoc, how do I know if the association is bidirectional?".

If $assoc is the inverse side ($assoc->isInverseSide()), its clear, its bidirectional. But if $assoc is the owning side, we dont know.
What we currently do to determine that in such a case looks as follows:

            if (isset($targetClass->inverseMappings[$assoc->sourceEntityName][$assoc->sourceFieldName])) {
                // Bi-directional
            }

So we check whether the target class has an inverse mapping to the source class. This is quite cumbersome. Additionally, we're usually only interested in the sourceFieldName of the inverse association.

Therefore, it would simplify internal code a lot if we simply introduced a "inversedBy" attribute on an association that is used on the owning side and that corresponds to "mappedBy" on the inverse side. Example:

/*** @Entity **/
class A {
...
   /****
    * @OneToOne(targetEntity="Other", inversedBy="a")
    * @JoinColumn(name="other_id", referencedColumnName="id")
    */
   private $other;
...
}
...
/*** @Entity **/
class Other {
    /*** @OneToOne(targetEntity="A", mappedBy="other") **/
    private $a;
}

This breaks BC. However, I think this is really necessary as it simplifies and speeds up the code, together with removing the inverseMappings attribute altogether.

So this should happen before beta.

Originally created by @doctrinebot on GitHub (Dec 6, 2009). Jira issue originally created by user romanb: The ClassMetadataInfo#inverseMappings attribute is an unnecessary complication. The problem comes down to: "Given an association $assoc, how do I know if the association is bidirectional?". If $assoc is the inverse side ($assoc->isInverseSide()), its clear, its bidirectional. But if $assoc is the owning side, we dont know. What we currently do to determine that in such a case looks as follows: ``` if (isset($targetClass->inverseMappings[$assoc->sourceEntityName][$assoc->sourceFieldName])) { // Bi-directional } ``` So we check whether the target class has an inverse mapping to the source class. This is quite cumbersome. Additionally, we're usually only interested in the sourceFieldName of the inverse association. Therefore, it would simplify internal code a lot if we simply introduced a "inversedBy" attribute on an association that is used on the owning side and that corresponds to "mappedBy" on the inverse side. Example: ``` /*** @Entity **/ class A { ... /**** * @OneToOne(targetEntity="Other", inversedBy="a") * @JoinColumn(name="other_id", referencedColumnName="id") */ private $other; ... } ... /*** @Entity **/ class Other { /*** @OneToOne(targetEntity="A", mappedBy="other") **/ private $a; } ``` This breaks BC. However, I think this is really necessary as it simplifies and speeds up the code, together with removing the inverseMappings attribute altogether. So this should happen before beta.
admin added the Improvement label 2026-01-22 12:31:58 +01:00
admin closed this issue 2026-01-22 12:31:59 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 31, 2010):

Comment created by romanb:

Patch is ready and will be committed within the next week.

@doctrinebot commented on GitHub (Mar 31, 2010): Comment created by romanb: Patch is ready and will be committed within the next week.
Author
Owner

@doctrinebot commented on GitHub (Apr 10, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Apr 10, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/d7c77b87fa2066dff479

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/d7c77b87fa2066dff479 - [10536_ddc193.patch](https://gist.github.com/d7c77b87fa2066dff479#file-10536_ddc193-patch)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#239