mike
mike

Reputation: 2760

How do I return a hash with relational data using parse.com?

I have a Post class and I want to get the products associated to it. I'd like to write a single query that fetches all of the posts with the products associated to them. Below is a rough idea of what I'd like the hash to looks like.

Schema:
Post - objectId, title
PostItem - post(pointer), product(pointer)
Product - objectId, title, price

Output I want {'results': [{'objectId':'blah', 'title':'The Post', 'products': [{'objectId':'14', 'title':'First product', 'price':'20' }, {'objectId':'26', 'title':'Second product', 'price':'55' }] }, {'objectId':'blah2', 'title':'Second post', [{'objectId':'38', 'title':'Some product', 'price':'54' }, {'objectId':'26', 'title':'Another Product', 'price':'88' }] }] }

Is this possible to do in one query? How would I do this using curl and parse.com?

Upvotes: 1

Views: 191

Answers (2)

Alex Mitchell
Alex Mitchell

Reputation: 400

You'll want to use the include key option alongside pointers. Since it's been nearly a year since you posted, I assume you figured it out, but lurkers can read more about this (in Javascript) here.

Upvotes: 0

zjaquish
zjaquish

Reputation: 271

If this is a many-to-many relationship, use a Parse relationship.

Upvotes: 0

Related Questions