title: Symfony Entity Field Type where clause in Query Builder not working on One-To-Many self referencing association
body: <p>I have an Entity called "InterestGroup" that has a self referencing association (adjacency list) in the form of properties "children" (one to many) and "parent" (many to one).</p>
  
  <p>In setting up a form type for InterestGroup, I'm attempting to provide a select list for the property parent, that has choices of all 'top level' interest groups (those whose 'parent' property is null).  When I add the the where clause and null parameter to the query_builder for the EntityType field, it always returns nothing, even when I have several top level (parent is null) interest groups persisted.  If I remove the where clause it will return all InterestGroups in the table.  I'm having a difficult time understanding why the where clause is not working.</p>
  
  <p><strong>This is the field in question:</strong></p>
  
  <pre><code>-&gt;add('parent',EntityType::class,
      array(
          'placeholder' =&gt; 'Top Level (No Parent)',
          'required' =&gt; false,
          'class' =&gt; 'Common\ContentBundle\Entity\InterestGroup',
          'query_builder' =&gt; function (EntityRepository $er) {
              return $er-&gt;createQueryBuilder('ig')
                -&gt;where('ig.parent = :n')
                -&gt;setParameter('n',null)
                -&gt;orderBy('ig.title', 'ASC');
          },
          'choice_label' =&gt; 'title'
      )
  )
  </code></pre>
  
  <p>The above will return an empty select menu.  By removing the where clause and the setparameter, I get all the InterestGroup Entities including all those that have null parents.</p>
  
  <p><strong>Following is the Entity Class for InterestGroup</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Common\ContentBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  use Symfony\Component\Validator\Constraints as Assert;
  use Gedmo\Mapping\Annotation as Gedmo;
  
  /**
   * InterestGroup
   *
   * @ORM\Table(name="interest_group")
   * @ORM\Entity(repositoryClass="Common\ContentBundle\Repository\InterestGroupRepository")
   */
  class InterestGroup
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="title", type="string", length=255, unique=true)
       * @Assert\NotBlank(message="This is a required field.")
       */
      private $title;
  
      /**
       * @ORM\OneToMany(targetEntity="InterestGroup", mappedBy="parent")
       */
      private $children;
  
      /**
       * @ORM\ManyToOne(targetEntity="InterestGroup", inversedBy="children")
       * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
       */
      private $parent;
  
      /**
       * @Gedmo\Slug(fields={"title"})
       * @ORM\Column(length=128, unique=true)
       */
      private $slug;
  
      // ...
      /**
       * @ORM\ManyToMany(targetEntity="Product", mappedBy="interestGroups")
       */
      private $products;
  
  
      /**
       * InterestGroup constructor.
       */
      public function __construct()
      {
          $this-&gt;children = new ArrayCollection();
          $this-&gt;products = new ArrayCollection();
  
      }
  
      /**
       * Get id
       *
       * @return int
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * @return string
       */
      public function getTitle()
      {
          return $this-&gt;title;
      }
  
      /**
       * @param string $title
       */
      public function setTitle($title)
      {
          $this-&gt;title = $title;
      }
  
  
      /**
       * @return mixed
       */
      public function getSlug()
      {
          return $this-&gt;slug;
      }
  
      /**
       * @return mixed
       */
      public function getChildren()
      {
          return $this-&gt;children;
      }
  
      /**
       * @param mixed $children
       */
      public function setChildren($children)
      {
          $this-&gt;children = $children;
      }
  
      /**
       * @return mixed
       */
      public function getParent()
      {
          return $this-&gt;parent;
      }
  
      /**
       * @param mixed $parent
       */
      public function setParent($parent)
      {
          $this-&gt;parent = $parent;
      }
  
      /**
       * @return mixed
       */
      public function getProducts()
      {
          return $this-&gt;products;
      }
  }
  </code></pre>
  
  <p><strong>And the Form Type Class:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Common\ContentBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Symfony\Component\Form\Extension\Core\Type\TextType;
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  use Doctrine\ORM\EntityRepository;
  
  class InterestGroupType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('title',TextType::class)
              -&gt;add('parent',EntityType::class,
                array(
                  'placeholder' =&gt; 'Top Level (No Parent)',
                  'required' =&gt; false,
                  'class' =&gt; 'Common\ContentBundle\Entity\InterestGroup',
                  'query_builder' =&gt; function (EntityRepository $er) {
                      return $er-&gt;createQueryBuilder('ig')
                        -&gt;where('ig.parent = :n')
                        -&gt;setParameter('n',null)
                        -&gt;orderBy('ig.title', 'ASC');
                  },
                  'choice_label' =&gt; 'title'
                )
              )
          ;
      }
  
      /**
       * @param OptionsResolver $resolver
       */
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Common\ContentBundle\Entity\InterestGroup'
          ));
      }
  }
  </code></pre>
  
  <p>Thanks in advance!</p>