DQL を使用して、SQL で次のようなクエリを作成したいと考えています。
select
e.*
from
e
inner join (
select
uuid, max(locale) as locale
from
e
where
locale = 'nl_NL' or
locale = 'nl'
group by
uuid
) as e_ on e.uuid = e_.uuid and e.locale = e_.locale
QueryBuilder を使用してクエリとサブクエリを生成しようとしました。彼らは自分で正しいことをしていると思いますが、結合ステートメントでそれらを組み合わせることができません。これがDQLで可能である場合、誰かがいますか? 実際のオブジェクトを返したいのですが、このクエリが実行されるオブジェクトがわからないため、ネイティブ SQL を使用できません (uuid および locale プロパティを持つ基本クラスしかわかりません)。
$subQueryBuilder = $this->_em->createQueryBuilder();
$subQueryBuilder
->addSelect('e.uuid, max(e.locale) as locale')
->from($this->_entityName, 'e')
->where($subQueryBuilder->expr()->in('e.locale', $localeCriteria))
->groupBy('e.uuid');
$queryBuilder = $this->_em->createQueryBuilder();
$queryBuilder
->addSelect('e')
->from($this->_entityName, 'e')
->join('('.$subQueryBuilder.') as', 'e_')
->where('e.uuid = e_.uuid')
->andWhere('e.locale = e_.locale');