1

I have two tables, RecCategory and Recommendation

RecCategory Table

Recommendation Table

How would I construct a HTTP request to retrieve all the RecCategory entries with their respective recommendations?

https://api.parse.com/1/classes/RecCategory/?include=recommendations results in an error

{
  "code": 102,
  "error": "field recommendations cannot be included because it is not a pointer to another object"
}

Thanks!

2 Answers 2

1

I do not believe this is possible in Parse, and I think it would probably be considered bad database design.

If it is the case that each Recommendation only belongs to One Category then this is what is known in Database terms as a many-to-one scenario, and what you want to do is store the recommendation's category in the table row with it. Then when you want to list the recommendations of a specific category you retrieve all recommendations for which the category field points to the category you are after.

In other words, remove the "Recommendations" field from the categories table, and then add a "Category" field (of type pointer to category) to the recommendations table. Because each recommendation has only one category, no array is needed.

If, however, you have a many-to-many relationship, where recommendations can come under many categories, then you want to create an intermediate table which pairs up recommendation pointers and category pointers.

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

4 Comments

Hmm I knew that, I must have accidentally added that recommendations field to the Category table. Is there a way I could query all the categories and their recommendations?
Yeah, just retrieve the categories table, and then for each record, retrieve all recommendations whose category field points to that category.
Wouldn't this result in a lot of queries? Would this be something I could do in Cloud Code so I don't have to do this client side?
That's true, it would. It depends what you want to do, really, but I suppose Ryan Kreager's solution might be best. Just pull the whole tables down and organise by category.
0

This isn't possible, but there are ways to work around the problem.

You can read more about it here: https://www.parse.com/questions/can-i-use-include-in-a-query-to-include-all-members-of-a-parserelation-error-102

You might be better off by pulling all the Recommendation objects and organizing them locally by their category.

Comments

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.