这适用于订购多对关联
/** @Entity **/
class User
{
// ...
/**
* @ORM\ManyToMany(targetEntity="Group")
* @ORM\OrderBy({"name" = "ASC"})
**/
private $groups;
}
但是,如果在我的Group Entity 中我有一个To-One association
(因此是 a foreign_key field
),我不能按 foreign_key 字段排序:
/** @Entity **/
class Group
{
// ...
/**
* @ORM\ManyToOne(targetEntity="Auxiliar", inversedBy="groups", fetch="EAGER")
* @ORM\JoinColumn(name="auxiliar_id", referencedColumnName="id")
**/
private $auxiliar;
}
为什么我不能按顺序排列组auxiliar_id
?这不起作用(500: unrecognized field
):
/** @Entity **/
class User
{
// ...
/**
* @ORM\ManyToMany(targetEntity="Group")
* @ORM\OrderBy({"auxiliar_id" = "ASC"})
**/
private $groups;
}
编辑:
也试过:auxiliar
,,,,groups.auxiliar
groups.auxiliar_id
auxiliar.id