I have 2 models, Recipe and Ingredient.
Basically I have a search function, where ideally when you search for an ingredient, it will return the recipes that uses said ingredient.
I manage to get the query working with the below. The only problem is, it only returns the ingredients that matches the query. I'd like for it to return all ingredients in the Recipe, if one of the ingredients matches the query. How would I adapt the below to do that?
For example if I search for tomato, I will get recipes with tomatoes win them, but the returned ingredients only includes tomatoes, but not the rest of the ingredients.
const recipes = await Recipe.findAll({
include: {
model: Ingredient,
where: {
name: {
[Op.iLike]: `%${ingredients}%`,
},
},
},
});
Thanks in advance!