0

I have two classes one is the User class and the other is NewsFeed. I need to join both the classes so that i can get the title present in the NewsFeed and the name present in User class.

I tried this but it fails

ParseQuery<ParseObject> query = ParseQuery.getQuery("Feed");
    query.whereEqualTo("AuthorId",ParseUser.getCurrentUser().getObjectId().toString());
    ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("User");
    relationQuery.whereMatchesQuery("ObjectId",query);
    relationQuery.find();

This always returns null if i remove the relation query i get all the data based on authorid.

2 Answers 2

2

You only need to query the feed, as you already have the user object (currentUser). Get the name from the currentUser object.

You are getting null since you are trying to match the Objectid with the result of the first query, which would be a list of one feed object.

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

7 Comments

what if i want to load other columns in the User class or join other class
Like any other object: ParseUser.getCurrentUser().getString("name");
How can we get the objectId from the query so that i can add them to relation because ParseRelation<ParseObject> requires to be a ParseObject and when i try to use getObjectId() it returns as a string
The objectId IS a String. If you want to relate two objects, you add the actual object to the ParseRelation. So, if you want to add a user to the relation with Feed, you create a field on Feed called "author" or "user" or whatever you think appropriate, and then you add the actual user object to the relation: feed.put("author", ParseUser.getCurrentUser()); - assuming that "feed" is the Feed object.
As a side note; you seldom need to define such a relation as a ParseRelation. A Pointer will cover your needs in most cases.
|
0

try this: 1)

  1. Replace your second line query.whereEqualTo("AuthorId",ParseUser.getCurrentUser().getObjectId().toString());

with this

query.whereEqualTo("AuthorId",ParseUser.getCurrentUser();
  1. And to get the comments for a post : Put a POINTER type field in COMMENTS class which points to the POST. Then remove the third line in the code you posted, replace it with query.whereEqualTo("field_pointerTopost",post_object_id);

1 Comment

1. This will only work if the AuthorId is a pointer. 2. Comments? The OP doesn't mention comments at all. And not POST either...

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.