0

In my data model, I have a Session class with an 'owner' field that points to a 'User' instance. I'm trying to retrieve all the sessions owned by a given user for whom I only have his objectId. Here is my query:

PFQuery *query = [PFQuery queryWithClassName:@"Session"];
NSString *userId = ...;
[query whereKey:@"owner" equalTo:[PFObject objectWithoutDataWithClassName:@"User" objectId:userId]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    //Here objects is always empty, even though I have several sessions whose 'owner' matches userId
}];

Obviously I'm doing something wrong here, but I don't know what. Can you help me?

3 Answers 3

3

A class with the name User is not the same as a PFUser. Internally I believe parse.com uses _User to refer to a PFUser object. Try changing the line:

[query whereKey:@"owner" equalTo:[PFObject objectWithoutDataWithClassName:@"User" objectId:userId]];

to

[query whereKey:@"owner" equalTo:[PFObject objectWithoutDataWithClassName:@"_User" objectId:userId]];

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

2 Comments

Thanks a lot. I wish that were documented somewhere.
It's actually visible in the Parse data browser, right beside the column name. Proper documentation would be awesome though.
0

I had same issue and solved it as below

[query whereKey:@"studId" equalTo:[PFObject objectWithoutDataWithClassName:@"_User" objectId:objUser.objectId]];

where studId is field of student class

Comments

-1

// Just add following code and that will be work and make sure you are passing objectID of user instead of just column name

[query include:@"owner"];

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.