Answer the question
In order to leave comments, you need to log in
Get a record from the database, if not found, return with other parameters?
There is a list of departments, with translations into different languages:
sections_i18n: id, section_id, name, lang_id
there are entries like this:
1, 1, development, NULL (NULL - стандартный перевод)
2, 1, разработка, 12 (12 - id русского языка)
WITH cte AS (
select ...
)
COALESCE( SELECT cte ..)
Answer the question
In order to leave comments, you need to log in
Why make conditions in SQL? Make two requests. If the first request results in NULL , then send a second request for the Default value.
$translation = Translation::find()->where(...)->one;
//если не нашли перевод, то по-умолчанию
if(!$translation) {
$translation = Translation::find()->where(...)->one
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question