这适用于订购多人关联
/** @Entity **/
class User
{
// ...
/**
* @ORM\ManyToMany(targetEntity="Group")
* @ORM\OrderBy({"name" = "ASC"})
**/
private $groups;
}
但是如果在我的群组实体中我有To-One association
(因此是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
答案 0 :(得分:1)
您可以在auxiliar_id
实体中添加Group
字段,并在水化后填充原则。