0

Let's say we're building a blog using Parse.com's javscript sdk where users can follow eachother and have a feed.

The 'Follow' class includes a pointer to the followee & follower. While the 'Post' class includes a pointer the creator (followee^).

if I now want to fetch all rows inside 'Post' where the creator equals followee and the user equals follower inside the 'Follow' class; then sort them using descending("createdAt"), how would one do that (efficiently)?

I have checked the api reference and there doesn't appear to be a straightforward answer to this issue: https://www.parse.com/docs/js/api/classes/Parse.Query.html

Any help is gladly welcome. Thanks.

1 Answer 1

2

This can be accomplished using a compound query, specifically matchesKeyInQuery. Compound queries only count as 1 API request.

First, create the inner query to find Follow objects where the requesting user is a follower.

var innerQuery = new Parse.Query("Follow");
innerQuery.equalTo("follower", request.user);

Next, create the outer query to find Post objects where their followee key matches the followee key in the results of our inner query.

var outerQuery = new Parse.Query("Post");
outerQuery.descending("createdAt");
outerQuery.matchesKeyInQuery("followee", "followee", innerQuery);

This will give you all of the Posts, in descending order by creation date, for all of the "followees" being followed the requesting user.

Cheers,

Russell

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

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.