Reputation: 49
I have a Parse object called Recipes
and a column called ingredients
, which is an array. I want to query my object list and retrieve a recipe based on some ingredients that I select.
If I use the whereKey:containsAllObjectsInArray:
message on the query object, I will get recipes with more ingredients. Also, whereKey:containedIn:
does not solve my problem. The retrieved objects should have an array of ingredients containing all my selected ingredients or only some of them. It should never have more ingredients than those I've selected.
Any ideas?
Upvotes: 1
Views: 95
Reputation: 8579
You could add an extra column to your recipe table "array count" for the number of ingredients in the recipe. Then do a multiple query:
[query whereKey:ingredients containsAllObjectsInArray:ingredientsArray];
[query whereKey: arrayCount equalTo:[ingredientsArray count]];
That way you are only returning things with the same number of ingredients and all the ones you listed.
Upvotes: 1
Reputation: 1284
You can maybe do - whereKey:notContainedIn:
for all the rest of the ingredients
(the ingredients this user doesn't have). and than the user will get only ingredients
he has.
Upvotes: 1