Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-357

Lazy-loading in OneToOne-bidirectional associations not working for inverse side


    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      XAMPP 1.7.3


      I am referring to the following situation:

      In this example: if I fetch an object of type "Customer" from my database, a second query is executed immediately that fetches the corresponding "Cart" even if I do not access the $cart property of "Customer". Annotating fetch="LAZY" to the $cart property does not make any difference. This is even worse in case of self-referencing objects, e.g. those having at most one parent object and at most one child object. Here, all associations are created by single database queries at once (e.g. fetching the child object, then the child of the child object and so forth).

      By contrast, OneToMany associations are lazy-loaded from the inverse side (as expected).

      Perhaps I should add, that I am using annotation mappings for my entities (no YAML, no XML).

        Issue Links


          m.walter Marcel Walter created issue -
          romanb Roman S. Borschel made changes -
          Field Original Value New Value
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Won't Fix [ 2 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira [ 10926 ] jira-feedback [ 14286 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira-feedback [ 14286 ] jira-feedback2 [ 16150 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 16150 ] jira-feedback3 [ 18403 ]
          romanb Roman S. Borschel made changes -
          Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
          hrajchert Hernan Rajchert made changes -
          Attachment getRelation.php [ 11415 ]
          hrajchert Hernan Rajchert made changes -
          Comment [ Hi, I've been faced with this issue some times. I tent to solve this by doing two unidirectional one-to-one. Then I deal with the non existing relationship using a method called getRelation that I defined in a BaseModel.

          I have created this method because Doctrine filled up with a Proxy when I fetch the entity without its relationship (then accesing the object would throw an Exception), and filled up with null when the object was eagerly fetched (left join) but no relationship was found.

          I think we could add this getRelation in the entitymanager or a trait after php 5.4.
          ocramius Marco Pivetta made changes -
          Link This issue is referenced by DDC-3011 [ DDC-3011 ]


            • Assignee:
              beberlei Benjamin Eberlei
              m.walter Marcel Walter
            • Votes:
              0 Vote for this issue
              9 Start watching this issue


              • Created: