0

我有两个学说实体“用户”和“属性”,如下所示。我需要构建一个查询来检索所有用户并按属性名称对它们进行排序,其中属性类型 = x。例如,获取所有用户并按“标题”对其进行排序。

SELECT u FROM User u JOIN u.attributes a ORDER BY a.name {something??} a.type = 'title'


class User {

    /**
     * @ManyToMany (targetEntity="Attribute", inversedBy="users", cascade={"persist"})
     * 
     */
    private $attributes;
}



class Attribute {

    /**
     * @Column (type="string", length=255, unique=false, nullable=false, name="name")
     * @FormElement (type="text")
     * @type string
     */
    protected $name;

    /**
     * @Column (type="string", unique=false, nullable=true, name="type")
     * @type string
     */
    private $type;

    /**
     * @Column (type="integer", length=11, unique=false, nullable=true, name="priority")
     * @type integer
     */
    private $priority;

    /**
     * @ManyToMany (targetEntity="User", mappedBy="attributes")
     */
    private $users;

}
4

1 回答 1

0

我认为这个查询是你正在寻找的:

SELECT u FROM User u JOIN u.attributes a WHERE a.type = 'title' ORDER BY a.name ASC
于 2010-11-17T08:27:07.587 回答