Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine 2 - Many-to-one of many-to-one lazy loading fails
    text
    copied!<p>My problem is related to the lazy-loading functionality of Doctrine 2.</p> <p>Let's say I have these 2 Entities:</p> <ul> <li>Area</li> <li>Venue</li> </ul> <p>Here are quick specs:</p> <ul> <li>An Area can contain other areas (sub-areas...)</li> <li>A Venue is located in only 1 area</li> <li>Area::getFullName() should output "Parent area name (if any) > Area name"</li> </ul> <p>My PHP Entities are:</p> <pre><code>class Area extends AbstractEntity { /** * @ORM\ManyToOne(targetEntity="Area", inversedBy="children") */ private $parent; public function getFullName() { if (!isset($this-&gt;fullName)) { $this-&gt;fullName = ($this-&gt;getParent() ? $this-&gt;getParent()-&gt;name . ' &gt; ' : '') . $this-&gt;name; } return $this-&gt;fullName; } class Venue extends AbstractEntity { /** * @ORM\ManyToOne(targetEntity="Area") */ private $area; </code></pre> <p>Let's say that area "Paris" contains a subarea named "Center"</p> <p>If I call:</p> <pre><code>$area = $repoArea-&gt;findByUrl("paris/center") echo $area-&gt;getFullName(); // --&gt; "Paris &gt; Center" </code></pre> <p>So far, so good.</p> <p>But let's say now, that the "Fouquet's" restaurant is one Venue in the center of Paris:</p> <pre><code>$venue = $repoVenue-&gt;findByName("Fouquet's"); echo $venue-&gt;getArea()-&gt;getFullName() // --&gt; " &gt; Center" </code></pre> <p>The parent area name (--> "Paris") is not output...</p> <pre><code>$this-&gt;fullName = ($this-&gt;getParent() ? $this-&gt;getParent()-&gt;name . ' &gt; ' : '') . $this-&gt;name; </code></pre> <p>But the parent Area Proxy Object is not NULL. It is just not initialized. And so calling the property "name" returns NULL.</p> <p>It seems that "double" (or "many-to-one of many-to-one"...) lazy loading fails. Something like:</p> <pre><code>$venue-&gt;getArea()-&gt;get(Parent)Area()-&gt;name </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload