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 ?
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With