title: Symfony querybuilder orderby failed
body: <p>in a querybuilder i do an orderby, but if i orderby a 'leftjoin' my orderby doesn't work and i don't understand why.</p>
  
  <p>My querybuilder :</p>
  
  <pre><code>        $qb = $this-&gt;createQueryBuilder('r')
          -&gt;leftJoin('r.clientCategorisation', 'cc')
          -&gt;leftJoin('cc.categorisation', 'c')
          -&gt;addOrderBy('c.id','ASC')
      $a_result = $qb-&gt;getQuery()-&gt;getResult();
      return $a_result;
  </code></pre>
  
  <p>If i orderby my 'r', its ok, but if i try to order 'c' that does't work ...
  I can order my 'c' asc if in my view html.twig i add  :</p>
  
  <pre><code>{{  clientCategorisation.categorisation.id}}
  </code></pre>
  
  <p>I don't understand why ??? And this method work only for 'asc', 'desc' failed.</p>
  
  <p>Edit : I have a datatable and in my table my order is on an object : </p>
  
  <pre><code>A_resultats = $this-&gt;_O_resultatsR-&gt;getByRapportOrderByCat($idRapport, $A_onglet);
  </code></pre>
  
  <p>getByRapportOrderByCat is my querybuilder.</p>
  
  <p>Then in a foreach :</p>
  
  <pre><code>foreach ( $A_resultats as $I_key =&gt; $O_resultat ) {
  </code></pre>
  
  <p>i construct my columns, and in this column 'analyse': </p>
  
  <pre><code>$A_valuesForTableau[$I_key]['analyse'] = $this-&gt;render('mypath', array(
                      'O_resultat'        =&gt; $O_resultat,
                      'A_clientCats'        =&gt; $A_clientCats,
              ))-&gt;getContent();
  </code></pre>
  
  <p>i give again my object $O_resultat to the template (if a comment this object in analyse my order is nice) and i think in the template my order from querybuilder is replace by order by asc (basic order by).</p>
  
  <p>Sorry for my bad english.</p>
  
  <p>edit2 : 
  Entity resutat : 
      class Resultat
      {
          /**
           * @var integer
           *
           * @ORM\Column(name="id", type="integer")
           * @ORM\Id
           * @ORM\GeneratedValue(strategy="AUTO")
           */
          private $id;</p>
  
  <pre><code>    /**
       * @ORM\ManyToOne(targetEntity="ClientCategorisation")
       * @ORM\JoinColumn(name="client_categorisation", referencedColumnName="id", onDelete="CASCADE", nullable=true)
       */
      private $clientCategorisation;
  
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set clientCategorisation
       *
       * @param ClientCategorisation $clientCategorisation
       * @return Resultat
       */
      public function setClientCategorisation(ClientCategorisation $clientCategorisation = null)
      {
          $this-&gt;clientCategorisation = $clientCategorisation;
  
          return $this;
      }
  
      /**
       * Get clientCategorisation
       *
       * @return ClientCategorisation 
       */
      public function getClientCategorisation()
      {
          return $this-&gt;clientCategorisation;
      }
  
  }
  </code></pre>
  
  <p>Entity clientcategorisation :</p>
  
  <pre><code>class ClientCategorisation 
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="Categorisation")
       * @ORM\JoinColumn(name="categorisation", referencedColumnName="id", onDelete="CASCADE")
       */
      private $categorisation;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set categorisation
       *
       * @param string $categorisation
       * @return ClientCategorisation
       */
      public function setCategorisation($categorisation)
      {
          $this-&gt;categorisation = $categorisation;
  
          return $this;
      }
  
      /**
       * Get categorisation
       *
       * @return string 
       */
      public function getCategorisation()
      {
          return $this-&gt;categorisation;
      }
  
  }
  </code></pre>
  
  <p>categorisation entity :</p>
  
  <pre><code>class Categorisation
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="nom", type="string", length=255)
       */
      private $nom;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="ordre", type="integer", nullable=true)
       */
      private $ordre;
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set nom
       *
       * @param string $nom
       * @return Categorisation
       */
      public function setNom($nom)
      {
          $this-&gt;nom = $nom;
  
          return $this;
      }
  
      /**
       * Get nom
       *
       * @return string
       */
      public function getNom()
      {
          return $this-&gt;nom;
      }
  
  
      /**
       * Set ordre
       *
       * @param integer $ordre
       * @return Categorisation
       */
      public function setOrdre($ordre)
      {
          $this-&gt;ordre = $ordre;
  
          return $this;
      }
  
      /**
       * Get ordre
       *
       * @return integer
       */
      public function getOrdre()
      {
          return $this-&gt;ordre;
      }
  }
  </code></pre>
  
  <p>edit2 : I have found a solution, when i use 'O_resultat' my order fail, so in my template i get 'A_resultats' and that work like this :</p>
  
  <pre><code>{% for O_resultats in A_resultats %}
      {% if O_resultats.id == O_resultat.id %}
  </code></pre>
  
  <p>and i replace in my vieuw O_resultat  by O_resultats</p>