title: Symfony2 and Entity Field : Expected argument of type "Doctrine\ORM\QueryBuilder", "NULL" given
body: <p>I have problems with my classes Symfony2.</p>
  
  <p>I have 3 classes "Niveau, Classe and Serie" that here. A class is related to a level and against a Series by Series Level and are in contact with several class. Here is the source code</p>
  
  <pre><code>/**
   * KS\SchoolBundle\Entity\Niveau
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="KS\SchoolBundle\Entity\NiveauRepository")
   */ 
  class Niveau
  {
  /**
   * @var integer $id
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string $niveau
   *
   * @ORM\Column(name="niveau", type="string", length=255)
   */
  private $niveau;
  
  /**
   * @var string $code
   * 
   * @ORM\Column(name="code", type="string", length=255)
   */
  private $code;
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set niveau
   *
   * @param string $niveau
   * @return Niveau
   */
  public function setNiveau($niveau)
  {
      $this-&gt;niveau = $niveau;
  
      return $this;
  }
  
  /**
   * Get niveau
   *
   * @return string 
   */
  public function getNiveau()
  {
      return $this-&gt;niveau;
  }
  
  /**
   * Set code
   *
   * @param string $code
   * @return Niveau
   */
  public function setCode($code)
  {
      $this-&gt;code = $code;
  
      return $this;
  }
  
  /**
   * Get code
   *
   * @return string 
   */
  public function getCode()
  {
      return $this-&gt;code;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>/**
   * KS\SchoolBundle\Entity\Serie
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="KS\SchoolBundle\Entity\SerieRepository")
   */
  class Serie
  {
  /**
   * @var integer $id
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string $serie
   *
   * @ORM\Column(name="serie", type="string", length=255)
   */
  private $serie;
  
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set name
   *
   * @param string $serie
   * @return Serie
   */
  public function setSerie($serie)
  {
      $this-&gt;serie = $serie;
  
      return $this;
  }
  
  /**
   * Get name
   *
   * @return string 
   */
  public function getSerie()
  {
      return $this-&gt;seriee;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>/**
   * KS\SchoolBundle\Entity\Classe
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="KS\SchoolBundle\Entity\ClasseRepository")
   */
  class Classe
  {
  /**
   * @var integer $id
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  
  /**
   *
   * @var type integer
   * 
   * @ORM\ManyToOne(targetEntity="KS\SchoolBundle\Entity\Niveau")
   * @ORM\JoinColumn(nullable=false)
   */
  private $niveau;
  
  
  /**
   *
   * @var type integer
   * 
   * @ORM\ManyToOne(targetEntity="KS\SchoolBundle\Entity\Serie")
   * @ORM\JoinColumn
   */
  private $serie;
  
  
  /**
   *
   * @var type string
   * 
   * @ORM\ManyToOne(targetEntity="KS\SchoolBundle\Entity\Section", inversedBy="classes")
   * @ORM\JoinColumn(nullable=false)
   */
  private $section;
  
  
  
  
  /**
   * Get id
   *
   * @return integer 
   */ 
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set niveau
   *
   * @param KS\School\Entity\Niveau $niveau
   * @return Classe
   */
  public function setNiveau(\KS\School\Entity\Niveau $niveau)
  {
      $this-&gt;niveau = $niveau;
  
      return $this;
  }
  
  /**
   * Get niveau
   *
   * @return KS\School\Entity\Niveau 
   */
  public function getNiveau()
  {
      return $this-&gt;niveau;
  }
  
  /**
   * Set serie
   *
   * @param KS\School\Entity\Serie $serie
   * @return Classe
   */
  public function setSerie(\KS\School\Entity\Serie $serie)
  {
      $this-&gt;serie = $serie;
  
      return $this;
  }
  
  /**
   * Get serie
   *
   * @return KS\School\Entity\Serie 
   */
  public function getSerie()
  {
      return $this-&gt;serie;
  }
  
  /**
   * Set section
   *
   * @param KS\School\Entity\Section $section
   * @return Classe
   */
  public function setSection(\KS\School\Entity\Section $section)
  {
      $this-&gt;section = $section;
  
      return $this;
  }
  
  /**
   * Get section
   *
   * @return KS\School\Entity\Section 
   */
  public function getSection()
  {
      return $this-&gt;section;
  }
  
  
  public function __toString() {
      return $this-&gt;getNiveau() . ' ' . $this-&gt;getSerie();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My problem is that entity in a field I want to display a dropdown that has value as a concatenation of the code level and series of Series I which procedé as follows</p>
  
  <pre><code>-&gt;add('class', 'entity', array(
                      'class' =&gt; 'KSSchoolBundle:Classe',
                      'property' =&gt; 'value',
                      'query_builder' =&gt; function (\KS\SchoolBundle\Entity\ClasseRepository $er) {
                              $results =  $er-&gt;findAllClassesByCodeAndSerie();
  
                              $data = array();
                              foreach ($results as $result) {
                                  $data[] = array(
                                      'id' =&gt; $result['id'],
                                      'value' =&gt; $result['code'] . ' ' . is_null($result['serie']) ? '' : $result['serie'],
                                  );
                              }
  
                              return $data;
                          },
                  )
          )
  </code></pre>
  
  <p>but nothing since there. query_builder return $data that is as you see an array. id must be the value of the option tag value and value should be what the user must see, but I do not see how to do this. The browser give this error <strong>Expected argument of type "Doctrine\ORM\QueryBuilder", "array" given</strong> </p>
  
  <p>I wonder if that would be a way to do it right the Class class at the <strong>__toString ()</strong> whereby it returns something like <strong>getNiveau (). getCode (). ''. getSerie (). getSerie ()</strong></p>
  
  <p>Please one hand it's been two days that I am on this form.</p>