Darussian
Darussian

Reputation: 1593

Parse - How to include array of pointers

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!

Upvotes: 1

Views: 1351

Answers (2)

Ryan Kreager
Ryan Kreager

Reputation: 3581

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.

Upvotes: 0

Luke
Luke

Reputation: 2486

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.

Upvotes: 1

Related Questions