title: symfony2 sort collection of objects by a property
body: <p>I have this entities:</p>
  
  <pre><code>class Categoria {
  
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue
       */
  
      protected $id;
  
      /** @ORM\Column(type="string", length=100) */
      protected $nom;
  
      /** @ORM\Column(type="string", length=100) */
      protected $slug;
  
      /** @ORM\Column(type="decimal", precision=3, scale=0) */
      protected $ordre;
  
      /** @ORM\Column(type="boolean", nullable=true) */
      protected $actiu=FALSE;
  
      /** @ORM\Column(type="decimal", precision=4, scale=0, nullable=true) */
      protected $enllaç=null;
  
      /** @ORM\OneToMany(targetEntity="LoPati\MenuBundle\Entity\subCategoria", mappedBy="categoria", cascade={"persist", "remove"} )*/
       protected $subCategoria; 
  public function __construct()
  {
      $this-&gt;subCategoria = new \Doctrine\Common\Collections\ArrayCollection();
  
  }
  
  /**
   * Add subCategoria
   *
   * @param LoPati\MenuBundle\Entity\subCategoria $subCategoria
   */
  public function addsubCategoria(\LoPati\MenuBundle\Entity\subCategoria $subCategoria)
  {
      $this-&gt;subCategoria[] = $subCategoria;
  }
  
  /**
   * Get subCategoria
   *
   * @return Doctrine\Common\Collections\Collection 
   */
  public function getSubCategoria()
  {
      return $this-&gt;subCategoria;
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>class SubCategoria {
  
  /**
   * @ORM\Id
   * @ORM\Column(type="integer")
   * @ORM\GeneratedValue
   */
  
  protected $id;
  
  /** @ORM\Column(type="string", length=100) */
  protected $nom;
  
  /** @ORM\Column(type="string", length=100) */
  protected $slug;
  
  /** @ORM\Column(type="decimal", precision=3, scale=0) */
  protected $ordre;
  
  /** @ORM\Column(type="boolean", nullable=true) */
  protected $actiu=FALSE; 
  
  /** @ORM\Column(type="boolean", nullable=true) */
  protected $llista=FALSE;
  
  /** @ORM\Column(type="decimal", precision=4, scale=0, nullable=true) */
  protected $enllaç=null;
  
  /** @ORM\ManyToOne(targetEntity="Categoria", inversedBy="subCategoria") */
  
  protected $categoria;
  </code></pre>
  
  <p>In Categoria entity I would like sort the collection of subcategoria Objects sort by <code>$ordre</code>.</p>
  
  <p>How I can do it ? Is possible do it in Twig templeate or in the definitios of Entity?</p>
  
  <p>Thanks</p>
  
  <p>Regards</p>