1

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?

3
  • That does not really make sense from a logical point of view... why would you have to specify ALL ingredients to get the recipe? Commented Jun 28, 2015 at 10:51
  • I want to retrieve the recipes that I can make using some ingredients (available in my house at that moment). I don't want to retrieve any recipes that requires more ingredients than I currently have available. Commented Jun 28, 2015 at 10:53
  • Can't you just fetch all the results for that ingredient set and then use some logic to filter out the ones with extra ingredients in your app? Commented Jun 28, 2015 at 13:25

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great, yeah parse has some weird limitations. Usually means you have to find a way around it changing your data model up a bit. glad I could help!
1

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.

1 Comment

That would be a valid workaround but I wouldn't want to send over the network all the ingredients (since there are a lot of them and I wouldn't want my app to use internet data in vain).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.