Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you take a look at one of your generated proxy classes, you'll see that the <code>__load()</code> and <code>__clone()</code> functions both throw the <code>EntityNotFoundException</code>.</p> <p>The <code>__load()</code> function is called when you "lazily" call the <code>getName()</code> function.</p> <pre><code>class ObjectB extends \Foo\Entity\ObjectB implements \Doctrine\ORM\Proxy\Proxy { private $_entityPersister; private $_identifier; public $__isInitialized__ = false; public function __construct($entityPersister, $identifier) { $this-&gt;_entityPersister = $entityPersister; $this-&gt;_identifier = $identifier; } /** @private */ public function __load() { if (!$this-&gt;__isInitialized__ &amp;&amp; $this-&gt;_entityPersister) { $this-&gt;__isInitialized__ = true; if (method_exists($this, "__wakeup")) { // call this after __isInitialized__to avoid infinite recursion // but before loading to emulate what ClassMetadata::newInstance() // provides. $this-&gt;__wakeup(); } if ($this-&gt;_entityPersister-&gt;load($this-&gt;_identifier, $this) === null) { throw new \Doctrine\ORM\EntityNotFoundException(); } unset($this-&gt;_entityPersister, $this-&gt;_identifier); } } ... public function getName() { $this-&gt;__load(); return parent::getName(); } ... } </code></pre> <p>You basically have a couple of options, the first being use a <code>try/catch</code> block.</p> <pre><code>try { $name = $objectB-&gt;getName(); } catch (\Doctrine\ORM\EntityNotFoundException $e) { $name = null; } </code></pre> <p>Or you can take a look at implementing the <a href="http://doctrine-orm.readthedocs.org/en/2.0.x/cookbook/implementing-wakeup-or-clone.html#safely-implementing-wakeup" rel="nofollow"><code>__wakeup()</code></a> function in <code>ObjectB</code> and possibly handling this yourself (though you'll more than likely need to throw an exception anyways).</p> <p>Lastly, if you are feeling ambitious, you can change the <code>Proxy</code> template. <code>\Doctrine\ORM\Proxy\ProxyFactory</code> contains the template.</p> <pre><code> /** Proxy class code template */ private static $_proxyClassTemplate = '&lt;?php namespace &lt;namespace&gt;; /** * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. */ class &lt;proxyClassName&gt; extends \&lt;className&gt; implements \Doctrine\ORM\Proxy\Proxy { private $_entityPersister; private $_identifier; public $__isInitialized__ = false; public function __construct($entityPersister, $identifier) { $this-&gt;_entityPersister = $entityPersister; $this-&gt;_identifier = $identifier; } /** @private */ public function __load() { if (!$this-&gt;__isInitialized__ &amp;&amp; $this-&gt;_entityPersister) { $this-&gt;__isInitialized__ = true; if (method_exists($this, "__wakeup")) { // call this after __isInitialized__to avoid infinite recursion // but before loading to emulate what ClassMetadata::newInstance() // provides. $this-&gt;__wakeup(); } if ($this-&gt;_entityPersister-&gt;load($this-&gt;_identifier, $this) === null) { throw new \Doctrine\ORM\EntityNotFoundException(); } unset($this-&gt;_entityPersister, $this-&gt;_identifier); } } </code></pre> <p>You should be able to get away with just removing the throwing of the <code>EntityNotFoundException</code> in the <code>__load()</code> and <code>__clone()</code> functions, though there might be unintended side effects. You'll also probably want to look at doing this change as a patch if you plan on upgrading Doctrine periodically.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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