I have a recipe table, linked to a seasons table via seasons_recipes. I want to filter the recipes by season ID, but if I apply the where condition on the include (in scope), the result only has the filtered seasons.
Recipes.addScope('search', (filters) => {
return {
include: [
{
model: Seasons,
as: 'seasons',
through: {attributes: []},
required: !!filters.seasons,
where: filters.seasons ? {id: {[Op.in]: filters.seasons}} : null,
whereMergeStrategy: 'and',
}
]
}
})
In my case, if a recipe has two seasons, only the season satisfying the where condition will be returned in the include.
Is it possible to filter recipes by season id and return recipes with all included seasons ?