連想テーブルによって教義2順
-
25-09-2019 - |
質問
私は2つの教義エンティティ「ユーザー」と「属性」は、以下に示されています。私はすべてのユーザーを取得し、どこ属性タイプ= 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;
}
解決
私はこのクエリは、あなたが探しているものだと思います:
SELECT u FROM User u JOIN u.attributes a WHERE a.type = 'title' ORDER BY a.name ASC
所属していません StackOverflow