My current task involves retrieving translations for various types of questions stored in my database. One issue I am facing is that some questions come with options while others do not.
const where: FindOptionsWhere<QuestionTranslation> = {
question: {
// some other props
options: { // this needs to be optional
translations: {
lang: In([localeCode, baseLocaleCode, LocaleCode.en]),
},
},
},
};
const questionTranslations = await this.questionTranslationRepository.find({
where,
});
If I exclude the options property, all translations are fetched but the ones related to options are missing for questions that have them. On the other hand, if I include it, questions without options are omitted.
I am looking for a solution that allows me to avoid making multiple calls to the database, with one call including and the other excluding the options property in the FindOptionsWhere object. It would be ideal to have something like:
options: {
[if exists]: {
translations: {
lang: In([localeCode, baseLocaleCode, LocaleCode.en]),
},
},
},
Do you think such an approach is feasible?