Question

I have undirectional one-to-one relation in status entity for attribute $views like this:

/**
 * @ORM\OneToOne(targetEntity="TB\WallBundle\Entity\BlogsViews", fetch="EXTRA_LAZY", cascade={"persist", "remove"})
 * @ORM\JoinColumn(name="blog_views_id", referencedColumnName="id")
 */
 protected $views;

The problem is when i do var_dump($status)

I see:

  protected 'views' => 
    object(TB\WallBundle\Entity\BlogsViews)[1072]
      private 'id' => int 5
      private 'blog_views_id' => int 61477
      private 'views' => int 0

But i do not need this value to be fetched always... why is the "extra_lazy" fetch not working? What am i doing wrong?

BTW: I DO NOT ACCESS THE $views attribute nowhere in code.

Was it helpful?

Solution

Doctrine creates a proxy-object that behaves like an instance of BlogViews.

This is the BlogViews "object" you're seeing if you inspect the object with var_dump.

Doctrine does not load all the properties of that object initially. The proxy handles fetching the properties when you attempt to access them!

This means there is actually no database-query as long as you don't try to access the lazy loading object/collection.

Keep in mind that var_dump does access these properties to show them to you!

This is expected behavior and doesn't mean the relation is not lazy-fetched.

I hope that clears things up a bit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top