title: Symfony - How to save foreign key in form "many-to-one"
body: <p>I'm new to Symfony 2 and I'm trying to build a form for a content type that has a foreign key.
  I have no idea about how to save the foreign key using the form.</p>
  
  <p>My two tables are "Category" and "Question". A question belongs to one category (many-to-one). So my Question.php file in Entity contains :</p>
  
  <pre><code>&lt;?php
  
  namespace Iel\CategorieBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Question
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="Iel\CategorieBundle\Entity\QuestionRepository")
   */
  class Question
  {
      /**
      * @ORM\ManyToOne(targetEntity="Iel\CategorieBundle\Entity\Categorie")
      * @ORM\JoinColumn(nullable=false)
      */
      private $categorie;
      /**
      * Set categorie
      *
      @param Iel\CategorieBundle\Entity\Categorie $categorie
      */
      public function setCategorie(\Iel\CategorieBundle\Entity\Categorie $categorie)
      {
          $this-&gt;categorie = $categorie;
      }
      /**
      * Get categorie
      *
      @return Iel\CategorieBundle\Entity\Categorie
      */
      public function getCategorie()
      {
          return $this-&gt;categorie;
      }
  </code></pre>
  
  <p>I've tryed build the controller function like this, but it's not a right syntax :</p>
  
  <pre><code>public function addquestionAction()
  {
      $question = new Question;
  
      $form = $this-&gt;createFormBuilder($question)
          -&gt;add('titre', 'text')
          -&gt;add('auteur', 'text')
          -&gt;add('contenu', 'textarea')
          -&gt;add('category_id', $this-&gt;getCategorie())    
          -&gt;getForm();    
  
      $request = $this-&gt;get('request');
  </code></pre>
  
  <p>I don't know how to write the current category_id in the Question's table using this form.</p>