I was wondering whether the following would be possible using Doctrine 2.4.
Suppose we have an entity that looks like this:
/** * @ORM\Entity * @ORM\Table */ class SomeEntity { /** * @ORM\Id * @ORM\Column(type="bigint") * @ORM\GeneratedValue */ protected $some_really_long_named_id; public function getSomeReallyLongNamedId() { return $this->some_really_long_named_id; } }
Since we work in IT and we're lazy, I added this method:
public function getId() { return $this->some_really_long_named_id; }
When this entity is proxied and we call getId()
on the proxy of this entity, the entity is lazy loaded. Which is weird, as that doesn't happen when we call getSomeReallyLongNamedId()
.
Apparently this has to do with some magic inside Doctrine's proxy objects. The generated proxy methods look like this:
/** * {@inheritDoc} */ public function getId() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); } /** * {@inheritDoc} */ public function getSomeReallyLongNamedId() { if ($this->__isInitialized__ === false) { return parent::getSomeReallyLongNamedId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSomeReallyLongNamedId', array()); return parent::getSomeReallyLongNamedId(); }
Is there any way to influence the ProxyGenerator
to make sure that when the getId()
method is called, it doesn't imply a lazy-load?