5

We are facing a problem reading data from relational tables. We have table1 ,which has in one of its columns a pointer to another table , called table2 . We need to get the data in table2 , from table1's pointer in one query request .

So, the query right now is :

PFQuery *query = [PFQuery queryWithClassName:@"table1"];
[query whereKey:@"completed"  equalTo:[NSNumber numberWithBool:NO]];
[query whereKey:@"userId" equalTo:[PFObject objectWithoutDataWithClassName:@"Users" objectId:@"someID"]];

[query  findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
 {
     if (!error)
     {

         //new user
         if(objects.count==0)
         {

         }

         else
         {
           //here we get "Users:vAJS2T96V1" ,which is the pointer to table2 ,but we need to go deeper to the other table 
           // in the same query, and get the data from table2 .
         }
     }

 }];

How do we get the data from table2, in one query ?

1
  • 1
    How are you doing on this? Have you gotten any further? Commented Feb 12, 2014 at 11:43

2 Answers 2

3

You use "includeKey" to fetch the data from the other table:

[query includeKey:@"Users"];

More info: http://blog.parse.com/2011/12/06/queries-for-relational-data/

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

2 Comments

I believe that this is incorrect. includeKey only works for Pointers not Relations despite the usage of the term "relational" in various places in that post. As mentioned in another post on this page, this clears it up: parse.com/questions/pointer-vs-relation
@JaredH The OP is about pointers: "We have table1 ,which has in one of its columns a pointer to another table , called table2 ." There is no mention anywhere of "Relations"
1

I have also faced this problem (in JS) at have not been able to fix it yet. Since the replication of this problem is very straightforward, I suppose that Parse.com lacks this functionality as of right now. There is an official answer (2) (taken from "parse questions archive") to the discussed problem that confirms my assumption.

Kevin Lacker (Parse staff)

In general "include" only works well for pointers. Relations might have far more objects being related to than can be included in a response.

Jamie Karraker (Parse staff)

Yes that is the limitation when you use relations.

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.