title: Symfony: How to pass Doctrine Collection to Form as default values?
body: <p>My action:</p>
  
  <pre><code>public function executeEdit(sfWebRequest $request)
  {
      // Get the object
      $article = $this-&gt;getRoute()-&gt;getObject();
  
      // Create the form
      $this-&gt;form = new ArticleEditForm( $article );
  }
  </code></pre>
  
  <p>You can see that <code>$article</code> is the Doctrine Collection that gets passed to the Form as default values. The <code>$article</code> object contains a fields like "title", "text", "author", etc.</p>
  
  <p>But this causes an error in the Form creation:</p>
  
  <pre><code>500 | Internal Server Error | Doctrine_Record_UnknownPropertyException
  Unknown record property / related component "_csrf_token" on "article"
  </code></pre>
  
  <p>So basically, the form is trying to use the Doctrine Collection to fill out default values for the form elements. But there obviously isn't a <code>csrf_token</code> in that object... But it's still trying to find one to use as the default value...</p>
  
  <p>And what happens if you have a form where there are always extra empty fields that are empty but others have default values that are passed. If those empty fields don't have set values in the Doctrine Collection then you get an error...</p>
  
  <p>Now, obviously I could just make a simple array ahead of time where I specify the default values and pass that:</p>
  
  <pre><code>$defaults = array( 'title' =&gt; $article-&gt;title, 'text' =&gt; $article-&gt;text, 'author' =&gt; $article-&gt;author );
  $this-&gt;form = new ArticleEditForm( $defaults);
  </code></pre>
  
  <p>This works. My problem is that the above "article" is an example for simplicity reasons. In reality my form has about 30 fields in it. So the only way that this solution would work is to have to manually specify 30 individual default values in an array. This is a poor solution from a maintenance point-of-view, obviously.</p>
  
  <p>I figure the Symfony developers are smart enough to come up with a good solution but I just can't find it... Any clues?</p>