I'm using the query below:
use Doctrine\ORM\Query\Expr\Join;
$query = $this->createQueryBuilder('ad')
->select('ad.id, ad.title, ad.year, ad.hours, ad.status')
->addSelect('rem.remark')
->leftJoin('ad.remark', 'rem', Join::WITH, "rem.language = 'NL'")
->getQuery()
->getResult();
This query is working fine and returns the remark of a ad in the Dutch language. The ad has a one-to-many relation with its remark.
Only I also have ads that have for example an English remark and not a Dutch one. The I will like to get the English remark of that one and on the others in the list still the Dutch remark. So too summarise making a priority list on the languages that are returned?
One way to solve this is to use an extra join without relation:
The idea is
Finally, the condition
customRem.id IS NULL
makes this work.Multiple languages solution
In the case of 3 supported languages, because DE > EN > NL, you could do:
For multiple languages and suppose a "customized" ability to order the languages, you could use:
Alternatively, you could create "lang_position" table(id, language, position) and join twice to get the position from the language.