在查詢生成器我做了一個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
你可以寫你想在樹枝中使用的字段嗎 –