質問ビルダでは、私はorderbyを行いますが、もし私が 'leftjoin'していれば、私のorderbyは動作せず、なぜ私は理解できません。symfony querybuilder orderby failed
マイquerybuilder:
私は私の 'R'、その[OK]をORDERBYが、私は仕事をdoes't 'C' ... を注文しようとした場合、私は私の 'C' を注文することができた場合 $qb = $this->createQueryBuilder('r')
->leftJoin('r.clientCategorisation', 'cc')
->leftJoin('cc.categorisation', 'c')
->addOrderBy('c.id','ASC')
$a_result = $qb->getQuery()->getResult();
return $a_result;
私の見解であれば昇順html.twig私は追加:
{{ clientCategorisation.categorisation.id}}
私はなぜ理解できないのですか?そして、このメソッドは 'asc'のためにのみ機能し、 'desc'は失敗しました。
編集:私はデータテーブルを持っているし、私のテーブルに注文が対象である:
A_resultats = $this->_O_resultatsR->getByRapportOrderByCat($idRapport, $A_onglet);
getByRapportOrderByCatは私querybuilderです。
foreach ($A_resultats as $I_key => $O_resultat) {
私は私の列を構築し、この欄に '分析':次にforeachの中
$A_valuesForTableau[$I_key]['analyse'] = $this->render('mypath', array(
'O_resultat' => $O_resultat,
'A_clientCats' => $A_clientCats,
))->getContent();
私はコメントがあれば(テンプレートに再び私のオブジェクト$ O_resultatを与えます私の注文を分析するにはこのオブジェクトがいいです)と私はテンプレートで私の注文は、ascii(基本的な順序で)順序で置き換えるquerybuilderからだと思う。
私の悪い英語のために申し訳ありません。
EDIT2: エンティティresutat: クラスResultat {/ ** * @var整数 * * @ORMの\カラム(名= "ID"、タイプ= "整数") * @ORM \ Id * @ORM \ GeneratedValue(戦略= "AUTO") */ プライベート$ 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 %}
と私はO_resultats
*私のorderbyは動作しません。*エラーメッセージを提供してください。 –
私はエラーメッセージがありませんが、もし私が持っている:1から9まで、私は1,2,3 ... 9を持っています。 ここで私は2,3,5,8,1 ... – Ygg69
あなたはあなたの枝に使用したいフィールドを書くことができます –