[DDC-193] Remove ClassMetadataInfo#inverseMappings Created: 06/Dec/09  Updated: 10/Apr/10  Resolved: 10/Apr/10

Status: Closed
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers, ORM
Affects Version/s: 2.0-ALPHA3
Fix Version/s: 2.0-BETA1
Security Level: All

Type: Improvement Priority: Critical
Reporter: Roman S. Borschel Assignee: Roman S. Borschel
Resolution: Fixed Votes: 1
Labels: None

Attachments: Text File ddc193.patch    

 Description   

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.



 Comments   
Comment by Roman S. Borschel [ 31/Mar/10 ]

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

Generated at Tue Jul 22 13:38:37 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.