IceCrew
IceCrew
PPrisma
Created by IceCrew on 12/10/2024 in #help-and-questions
Retrieve accurate data
Hi! Hope you're well! I have recipe categories (lasagne, chocolate cake...) that have recipes (vegetarian lasagne, gluten-free chocolate cake...). These recipes have ingredients (butter, eggs...) On the customer's side, I have a selector that allows the user to select the ingredients they want and don't want to have in their search. Example: the user wants recipes that have eggs AND apples, but NO cheese. A recipes with eggs, apples and butter must be displayed. Here's my query:
return await prisma.recipesCategory.findMany({
where: {
recipes: {
some: {
ingredients: {
some: {
ingredientId: {
in: ingredientsIdsWanted
},
},
every: {
ingredientId: {
notIn: ingredientsIdsNotWanted,
},
},
},
},
},
},
});
return await prisma.recipesCategory.findMany({
where: {
recipes: {
some: {
ingredients: {
some: {
ingredientId: {
in: ingredientsIdsWanted
},
},
every: {
ingredientId: {
notIn: ingredientsIdsNotWanted,
},
},
},
},
},
},
});
the problem I have with this query is that it returns the recipe even if it contains only one ingredient in the list, which is normal since there's the some However, if I put an every and the recipe contains additional ingredients, it won't be displayed even if the conditions are met. I've been trying to find a solution for I don't know how long, and I just can't seem to get it, I feel like I'm going crazy or maybe it's simple and I'm looking for too complicated ahah thanks in advance!
8 replies