Symfony 2 doctrine DQL order by two fields
<p>Hi guys i have two objects Point and Subpoint when i got from the repository with custom DQL The point i want to order the Points by field ord and the Subpoints to field ord.</p>

<p>Here is the Entities:</p>

<pre><code>namespace George\ArchitectureBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;

/**
 * Point
 *
 * @ORM\Table()
 *    @ORM\Entity(repositoryClass="George\ArchitectureBundle\Entity\PointRepository")
 * @Vich\Uploadable
 */
class Point
{
use Translatable;
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var Object
 * @Gedmo\SortableGroup
 * @ORM\ManyToOne(targetEntity="George\ObjectsBundle\Entity\Object", inversedBy="architecturespoints")
 * @ORM\JoinColumn(name="object_id", referencedColumnName="id")
 */
private $object;

/**
 * @ORM\OneToMany(targetEntity="George\ArchitectureBundle\Entity\Subpoint", mappedBy="point")
 */
private $subpoints;


/**
 * @var integer
 * @Gedmo\SortablePosition
 * @ORM\Column(name="ord", type="integer")
 */
private $ord;

/**
 * @var \DateTime
 * @Gedmo\Timestampable(on="update")
 * @ORM\Column(name="updated", type="datetime")
 */
private $updated;

/**
 * @var \DateTime
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(name="created", type="datetime")
 */
private $created;

public function __construct()
{
    $this-&gt;subpoints = new ArrayCollection();
}
/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this-&gt;id;
}

/**
 * @return Object
 */
public function getObject()
{
    return $this-&gt;object;
}

/**
 * @param Object $object
 */
public function setObject($object)
{
    $this-&gt;object = $object;
}
/**
 * @return int
 */
public function getOrd()
{
    return $this-&gt;ord;
}

/**
 * @param int $ord
 */
public function setOrd($ord)
{
    $this-&gt;ord = $ord;
}
/**
 * @return \DateTime
 */
public function getUpdated()
{
    return $this-&gt;updated;
}

/**
 * @return \DateTime
 */
public function getCreated()
{
    return $this-&gt;created;
}

/**
 * @return mixed
 */
public function getSubpoints()
{
    return $this-&gt;subpoints;
}

/**
 * NOTE: This is not a mapped field of entity metadata, just a simple property.
 *
 * @Vich\UploadableField(mapping="point_image", fileNameProperty="imageName")
 *
 * @var File
 */
private $imageFile;

/**
 * @ORM\Column(type="string", length=255, nullable=true)
 *
 * @var string
 */
private $imageName;

/**
 * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
 * of 'UploadedFile' is injected into this setter to trigger the  update. If this
 * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
 * must be able to accept an instance of 'File' as the bundle will inject one here
 * during Doctrine hydration.
 *
 * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
 */
public function setImageFile(File $image = null)
{
    $this-&gt;imageFile = $image;

    if ($image) {
        // It is required that at least one field changes if you are using doctrine
        // otherwise the event listeners won't be called and the file is lost
        // $this-&gt;setModefied(new \DateTime('now')) ;
    }
}

/**
 * @return File
 */
public function getImageFile()
{
    return $this-&gt;imageFile;
}

/**
 * @param string $imageName
 */
public function setImageName($imageName)
{
    $this-&gt;imageName = $imageName;
}

/**
 * @return string
 */
public function getImageName()
{
    return $this-&gt;imageName;
}
}
</code></pre>

<p>Subpoint:</p>

<pre><code>namespace George\ArchitectureBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;


 /**
 * Subpoint
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="George\ArchitectureBundle\Entity\SubpointRepository")
 * @Vich\Uploadable
 */
class Subpoint
{
use Translatable;

/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var Points
 * @Gedmo\SortableGroup
 * @ORM\ManyToOne(targetEntity="George\ArchitectureBundle\Entity\Point", inversedBy="subpoints")
 */
private $point;

/**
 * @var integer
 * @Gedmo\SortablePosition
 * @ORM\Column(name="ord", type="integer")
 */
private $ord;



/**
 * @var \DateTime
 * @Gedmo\Timestampable(on="update")
 * @ORM\Column(name="updated", type="datetime")
 */
private $updated;


/**
 * @var \DateTime
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(name="created", type="datetime")
 */
private $created;

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this-&gt;id;
}

/**
 * @return Points
 */
public function getPoint()
{
    return $this-&gt;point;
}

/**
 * @param Points $point
 */
public function setPoint($point)
{
    $this-&gt;point = $point;
}
/**
 * NOTE: This is not a mapped field of entity metadata, just a simple property.
 *
 * @Vich\UploadableField(mapping="point_image", fileNameProperty="imageName")
 *
 * @var File
 */
private $imageFile;

/**
 * @ORM\Column(type="string", length=255, nullable=true)
 *
 * @var string
 */
private $imageName;


/**
 * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
 * of 'UploadedFile' is injected into this setter to trigger the  update. If this
 * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
 * must be able to accept an instance of 'File' as the bundle will inject one here
 * during Doctrine hydration.
 *
 * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
 */
public function setImageFile(File $image = null)
{
    $this-&gt;imageFile = $image;

    if ($image) {
        // It is required that at least one field changes if you are using doctrine
        // otherwise the event listeners won't be called and the file is lost
        // $this-&gt;setModefied(new \DateTime('now')) ;
    }
}

/**
 * @return File
 */
public function getImageFile()
{
    return $this-&gt;imageFile;
}

/**
 * @param string $imageName
 */
public function setImageName($imageName)
{
    $this-&gt;imageName = $imageName;
}

/**
 * @return string
 */
public function getImageName()
{
    return $this-&gt;imageName;
}
/**
 * @return \DateTime
 */
public function getUpdated()
{
    return $this-&gt;updated;
}

/**
 * @return \DateTime
 */
public function getCreated()
{
    return $this-&gt;created;
}

/**
 * @return int
 */
public function getOrd()
{
    return $this-&gt;ord;
}

/**
 * @param int $ord
 */
public function setOrd($ord)
{
    $this-&gt;ord = $ord;
}

}
</code></pre>

<p>Repository Point and here i want when i got the Point to be oredered by ord and the subpoints to be ordered by ord:</p>

<pre><code>namespace George\ArchitectureBundle\Entity;

/**
 * PointRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class PointRepository extends \Doctrine\ORM\EntityRepository
{
public function getPointsByObject($object)
{

    $em = $this-&gt;getEntityManager();
    $query = $em-&gt;createQuery("SELECT p  FROM George\ArchitectureBundle\Entity\Point p WHERE p.object =".$object." ORDER BY p.ord ASC");
    return  $query-&gt;getResult();


}
}
</code></pre>

<p>But when i put in the creatQuery in Point repository</p>

<pre><code>"SELECT p  FROM George\ArchitectureBundle\Entity\Point p WHERE p.object =".$object." ORDER BY p.ord ASC, p.subpoints.ord ASC "
</code></pre>

<p>I got error:</p>

<pre><code>[Semantical Error] line 0, col 107 near 'ord ASC ': Error: Class George\ArchitectureBundle\Entity\Point has no field or association named subpoints.ord 
</code></pre>

<p><strong>EDIT</strong>
The solution to the problem is this with query builder with guidance of @Yoshi and @Veve:</p>

<pre><code>public function getPointsByObject($object)
{

    $em = $this-&gt;getEntityManager();
  //  $query = $em-&gt;createQuery("SELECT p  FROM George\ArchitectureBundle\Entity\Point p left join George\ArchitectureBundle\Entity\Subpoint s WITH s.point = p  WHERE p.object =".$object." ORDER BY p.ord ASC, s.ord ASC");
    $qb = $em-&gt;createQueryBuilder();
    $qb-&gt;select('p')
        -&gt;from('George\ArchitectureBundle\Entity\Point','p')
        -&gt;where(' p.object =:object')
        -&gt;leftJoin('George\ArchitectureBundle\Entity\Subpoint', 's', 'WITH', 's.point = p')
        -&gt;orderBy('p.ord','ASC')
        -&gt;orderBy('s.ord','ASC');

    $qb-&gt;setParameters(array(
        'object' =&gt; $object
    ));
    $query= $qb-&gt;getQuery();

    return  $query-&gt;getResult();


}
</code></pre>