Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATE</strong> </p> <p>Given your edit, the problem isn't proxy objects at all, it's how you're using your $query object.</p> <p><code>$query-&gt;getResult()</code> will return an array of results. In an instance like this where you're limiting the result set to a max of 1 row, it'll return an array with one entry, but still an array. Twig chokes on this when trying to use accessor methods, naturally.</p> <p>What you'll want to do is use <code>$query-&gt;getSingleResult()</code> instead. Note that Doctrine will throw a non-unique result exception if the query returns more than one row, so you need to be sure to use it with <code>setMaxResults(1)</code> like you're doing if the query can possibly return multiple results.</p> <p><strong>END UPDATE</strong></p> <p>From the documentation on <a href="http://www.doctrine-project.org/docs/orm/2.0/en/reference/configuration.html#reference-proxies">reference proxies</a>:</p> <blockquote> <p>Here $item is actually an instance of the proxy class that was generated for the Item class but your code does not need to care. In fact it <strong>should not care</strong>. Proxy objects should be transparent to your code.</p> </blockquote> <p>Emphasis theirs. Proxies should be transparent to your code, and exist to improve performance where possible; however, if you have a pressing need to eager-load part of the query, you can either set the fetch mode in your entity configuration file, or check out <a href="http://www.doctrine-project.org/docs/orm/2.1/en/reference/dql-doctrine-query-language.html?highlight=eager#temporarily-change-fetch-mode-in-dql">this section</a> of the docs:</p> <pre><code>$query = $em-&gt;createQuery("SELECT u FROM MyProject\User u"); $query-&gt;setFetchMode("MyProject\User", "address", "EAGER"); $query-&gt;execute(); </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