return $this->connection->
createQueryBuilder() ->
from('s_emotion', 'emo'
) ->
join( 'emo',
's_emotion_categories',
'emo_cat',
'emo.id = emo_cat.emotion_id'
) ->
leftJoin('emo_cat', 's_categories', 'cat', 'emo_cat.category_id = cat.id'
) ->
where('emo.active = 1'
) ->
andWhere(sprintf('emo_cat.category_id IN (%s)',
$this->
prepareSubQuery()->
getSQL())) ->
andWhere('emo.valid_to > NOW() OR emo.valid_to IS NULL'
);
} /**
* @return QueryBuilder
*/
private function prepareSubQuery() { return parent::
getBaseQuery() ->
addSelect(['cat.id'
]);
}}