I'm building a query as an EntityRepository with querybuilder. I have a ManyToOne relationship (by the ID) im trying to order the query by a value of the relationship instead. Code snippets below.
namespace AppBundle\Entity\Repository;
class ContratoRepository extends EntityRepository
{
public function getWithoutParams($ops)
{
$query=$this->createQueryBuilder('e')
->orderBy('e.proc','ASC');
return $query->getQuery()->getResult();
}
Now my entity
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\ContratoRepository")
*/
class Contrato
{
...
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\ContratosAdmin\Proc")
* @ORM\JoinColumn(name="id_proc", referencedColumnName="id_proc")
* @ORM\OrderBy({"name" = "ASC"})
**/
private $proc;
Now my question is, is it possible to order by the "name" field inside my Proc Entity ? as it is now, it's ordering by it's Id.
Thank you, Regards.
join
request in theContratoRepository
to retrieve the data ofContrato
ANDProc
entity. then in your queryBuilder request you will have something like->orderBy('p.name','ASC');
wherep
represent yourProc
entity. – Grechka Vassili