title: Sorting joined table with KnpPaginatorBundle
body: <p>I set up a test to get more familiar with Symfony2 and KnpPaginatorBundle. I have a table with pets that references the pet animal type (<code>Dog</code>, <code>Cat</code>, Etc). I can sort by the <code>id</code>, <code>name</code>, but when I try to sort by animal <code>type</code> I get an error message stating: </p>
  
  <blockquote>
    <p>There is no such field [animalkind] in the given Query component, aliased by [a]</p>
  </blockquote>
  
  <p>I have tried various field names, but nothing seems to work. </p>
  
  <p>Entity: <code>MyPets.php</code></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  namespace Xyz\TestBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * MyPet
   */
  
  class MyPet
  {
      /**
       * @var integer
       */
      private $id;
  
      /**
       * @var string
       */
      private $name;
  
      /**
       * Set id
       *
       * @param integer $id
       * @return MyPet
       */
      public function setId($id)
      {
          $this-&gt;id = $id;
          return $this;
      }
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set name
       *
       * @param string $name
       * @return MyPet
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string 
       */
      public function getName()
      {
          return $this-&gt;name;
      }
      /**
       * @var \Xyz\TestBundle\Entity\AnimalKind
       */
      private $AnimalKind;
  
      /**
       * Set AnimalKind
       *
       * @param \Xyz\TestBundle\Entity\AnimalKind $animalKind
       * @return MyPet
       */
      public function setAnimalKind(\Xyz\TestBundle\Entity\AnimalKind $animalKind)
      {
          $this-&gt;AnimalKind = $animalKind;
          return $this;
      }
  
      /**
       * Get AnimalKind
       *
       * @return \Xyz\TestBundle\Entity\AnimalKind 
       */
      public function getAnimalKind()
      {
          return $this-&gt;AnimalKind;
  
      }
  }
  </code></pre>
  
  <p>Entity: <code>AnimalKind.php</code></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  namespace Xyz\TestBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * AnimalKind
   */
  class AnimalKind {
  
      /**
       * @var integer
       */
      private $id;
  
      /**
       * @var string
       */
      private $type;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId() {
          return $this-&gt;id;
      }
  
      /**
       * Set type
       *
       * @param string $type
       * @return AnimalKind
       */
      public function setType($type) {
          $this-&gt;type = $type;
  
          return $this;
      }
  
      /**
       * Get type
       *
       * @return string 
       */
      public function getType() {
          return $this-&gt;type;
      }
  
      /**
       * @var \Doctrine\Common\Collections\Collection
       */
      private $MyPets;
  
      /**
       * Constructor
       */
      public function __construct() {
          $this-&gt;MyPets = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      /**
       * Add MyPets
       *
       * @param \Xyz\TestBundle\Entity\MyPet $myPets
       * @return AnimalKind
       */
      public function addMyPet(\Xyz\TestBundle\Entity\MyPet $myPets) {
          $this-&gt;MyPets[] = $myPets;
  
          return $this;
      }
  
      /**
       * Remove MyPets
       *
       * @param \Xyz\TestBundle\Entity\MyPet $myPets
       */
      public function removeMyPet(\Xyz\TestBundle\Entity\MyPet $myPets) {
          $this-&gt;MyPets-&gt;removeElement($myPets);
      }
  
      /**
       * Get MyPets
       *
       * @return \Doctrine\Common\Collections\Collection 
       */
      public function getMyPets() {
          return $this-&gt;MyPets;
      }
  
      public function __toString() {
          return $this-&gt;getType();
      }
  
  }
  </code></pre>
  
  <p>Controller: <code>MyPetController.php</code> (<code>IndexAction</code>)</p>
  
  <pre class="lang-php prettyprint-override"><code>    public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $query = $em-&gt;createQuery("SELECT a FROM XyzTestBundle:MyPet a");
  
          $paginator  = $this-&gt;get('knp_paginator');
  
          $pagination = $paginator-&gt;paginate($query,$this-&gt;get('request')-&gt;query-&gt;get('page', 
            1)/*page number*/,15/*limit per page*/);
  
          return $this-&gt;render('XyzTestBundle:MyPet:index.html.twig', array(
           'pagination' =&gt; $pagination,
  
          ));
      }
  </code></pre>
  
  <p>View: <code>MyPet/index.html.twig</code> (snipped)</p>
  
  <pre><code>&lt;table class="records_list"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              {# sorting of properties based on query components #}
              &lt;th&gt;{{ knp_pagination_sortable(pagination, 'Id', 'a.id') }}&lt;/th&gt;
              &lt;th&gt;{{ knp_pagination_sortable(pagination, 'Name', 'a.name') }}&lt;/th&gt;
              &lt;th&gt;{{ knp_pagination_sortable(pagination, 'kind', 'a.animalkind') }}&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      {% for mypet in pagination %}
          &lt;tr&gt;
              &lt;td&gt;&lt;a href="{{ path('xyz_mypet_show', { 'id': mypet.id }) }}"&gt;{{ mypet.id }}&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;{{ mypet.name }}&lt;/td&gt;
              &lt;td&gt;{{ mypet.animalkind }}&lt;/td&gt;
          &lt;/tr&gt;
      {% endfor %}
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Can anyone give me any insight as to the problem?</p>