在查询生成器我做了一个orderby,但如果我orderby'leftjoin'我orderby不起作用,我不明白为什么。Symfony查询生成器orderby失败
我的QueryBuilder:
$qb = $this->createQueryBuilder('r')
->leftJoin('r.clientCategorisation', 'cc')
->leftJoin('cc.categorisation', 'c')
->addOrderBy('c.id','ASC')
$a_result = $qb->getQuery()->getResult();
return $a_result;
如果我排序依据我的“R”,其确定,但如果我尝试命令“C”是简化版,工作...... 我可以为了我的“C” asc如果在我看来html.twig我加:
{{ clientCategorisation.categorisation.id}}
我不明白为什么?而这种方法只适用于'asc','desc'失败。
编辑:我有一个DataTable,并在我的表我的订单是在对象上:
A_resultats = $this->_O_resultatsR->getByRapportOrderByCat($idRapport, $A_onglet);
getByRapportOrderByCat是我的QueryBuilder。
然后在foreach:
foreach ($A_resultats as $I_key => $O_resultat) {
我建我的专栏,并在此列 '分析':
$A_valuesForTableau[$I_key]['analyse'] = $this->render('mypath', array(
'O_resultat' => $O_resultat,
'A_clientCats' => $A_clientCats,
))->getContent();
我给再我的目标$ O_resultat到模板(如果评论这个对象在分析我的订单是很好的),我认为在模板中,我的来自querybuilder的订单被asc(基本订单by)替代。
对不起,我的英语不好。
EDIT2: 实体resutat: 类Resultat { /** * @var整数 * * @ORM \柱(名称= “ID”,类型= “整数”) * @ORM \ Id * @ORM \ GeneratedValue(strategy =“AUTO”) */ private $ id;
/**
* @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->id;
}
/**
* Set clientCategorisation
*
* @param ClientCategorisation $clientCategorisation
* @return Resultat
*/
public function setClientCategorisation(ClientCategorisation $clientCategorisation = null)
{
$this->clientCategorisation = $clientCategorisation;
return $this;
}
/**
* Get clientCategorisation
*
* @return ClientCategorisation
*/
public function getClientCategorisation()
{
return $this->clientCategorisation;
}
}
实体clientcategorisation:
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->id;
}
/**
* Set categorisation
*
* @param string $categorisation
* @return ClientCategorisation
*/
public function setCategorisation($categorisation)
{
$this->categorisation = $categorisation;
return $this;
}
/**
* Get categorisation
*
* @return string
*/
public function getCategorisation()
{
return $this->categorisation;
}
}
分类实体:
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->id;
}
/**
* Set nom
*
* @param string $nom
* @return Categorisation
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set ordre
*
* @param integer $ordre
* @return Categorisation
*/
public function setOrdre($ordre)
{
$this->ordre = $ordre;
return $this;
}
/**
* Get ordre
*
* @return integer
*/
public function getOrdre()
{
return $this->ordre;
}
}
EDIT2:我已经找到了解决办法,当我在我的模板中使用 'O_resultat' 我的订单失败,所以我得到'A_resultats',那样的工作:
{% for O_resultats in A_resultats %}
{% if O_resultats.id == O_resultat.id %}
和我在vieuw O_resultat替代由O_resultats
*我的订单不起作用*请提供错误消息。 –
我没有错误信息,但如果我有:1至9,在ASC我有1,2,3 ... 9。 在这里我有2,3,5,8,1 ... – Ygg69
你可以写你想在树枝中使用的字段吗 –