title: symfony2 ContextErrorException: Catchable Fatal Error: Object of class Proxies\__CG__\...\Entity\... could not be converted to string
body: <p>I have encountered something weird:</p>
  
  <p>I created three doctrine entities via <code>app/console doctrine:generate:entity</code>:</p>
  
  <ul>
  <li>Category</li>
  <li>User</li>
  <li>Post</li>
  </ul>
  
  <p>I set up the relationships and everything works fine with the fixtures data (<code>app/console doctrine:fixtures:load</code>).</p>
  
  <p>A post belongs to a single category (category_id), and has one author (user_id).</p>
  
  <p>I used <code>app/console doctrine:generate:crud</code> to get CRUD operations for all my entities.</p>
  
  <p>When I update a post, I get this strange error:</p>
  
  <blockquote>
    <p>ContextErrorException: Catchable Fatal Error: Object of class Proxies__CG__...\BlogBundle\Entity\Category could not be converted to string</p>
  </blockquote>
  
  <p>In order to correctly display the dropdown fields I use in <code>PostType()</code>:</p>
  
  <pre><code>$builder ....
    -&gt;add('categoryId','entity', array(
       'class' =&gt; 'HotelBlogBundle:Category',
       'property'=&gt;'name'
  ))
  -&gt;add('userId','entity',array(
       'class'=&gt;'UserBundle:User',
       'property'=&gt;'username'
  ))
  </code></pre>
  
  <p>Since I specify the <code>property</code> option I don't need a <code>__toString()</code> in my Entity classes.</p>
  
  <p>If I create a <code>__toString()</code> like this (both in Category &amp; User Entities), the error is gone and works:</p>
  
  <pre><code>public function __toString()
  {
      return (string) $this-&gt;getId();
  }
  </code></pre>
  
  <p>I am not sure if I do it the right way. </p>
  
  <p>Also, since a <code>Category</code> &amp; <code>User</code> object is passed to <code>category_id</code> and <code>user_id</code> fields, Doctrine (or Symfony) should be able to figure out the id column. What am I missing? Is there another way of doing this?</p>