I have a UserToMessage
table which has a pointer to user called thisUser
and a pointer to message called msg
The message tab
Ok this question is really confusing. If I understood correctly, You want to query the UserToMessage
table and include two conditions? If so you could do it like this:
[query whereKey:@"msg" equalTo:MSG_POINTER];
[query whereKey:@"thisUser" equalTo:PF_USER_POINTER];
If this is not the case please update your question to reflect what exactly you need.
This will work.
PFQuery *query = [PFQuery queryWithClassName:@"UserToMessage"];
[query includeKey:@"msg"];
[query includeKey:@"msg.creator"];
// Add constraints on query
...
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(error) return;
// Do action
...
}];
Instead of asking yourself how you can include info from multiple tables in a JOIN-like query, you should ask yourself if you've designed the database model your app needs.
What you've written about your model sounds very SQL-ish. That's ok, though, as most people coming to parse.com and other NoSQL-backed services come from the SQL world. However, simply transfering a SQL database design into Parse does not usually provide an optimal solution.
Instead, focus on the queries first and determine what data they need to return. If you find you need data from 3 different classes returned in a query, that is a fault of the model. Developing an app for portable devices, you need to focus on query performance and calculation overhead.
You should design your database model in such a way that most (if not all) of your data will be accessible in as few queries as possible. Preferably one.
Typical solutions to this problem revolves around denormalisation and eventual consistency. For example, in a Twitter-like app, if you want to retrieve the posts made by the people you follow, it is not scaleable to get this by first querying for a person's "followings" and then query the tweet table for all tweets made by those people. It could work for a few followings and posts, but it would be unfeasible if you followed 100.000 people.
In a NoSQL scenario, when someone published a tweet, this post would be stored in the tweet table, and you would store a pointer to that tweet in an array in my feed object and in the feed objects of each and every person following the author of the tweet!
I know this seems odd (crazy, even) from a SQL database viewpoint, but not so for NoSQL systems. If I later deleted a tweet, the tweet would need to be removed from possibly 359.000 feed objects (if I was Barack Obama). This would not be immediate - hence "eventual consistency".
I recommend you sit down with pen and paper and rethink your database model based on the data you need to retrieve.
[includeKey:@"message.creator"]
You can even do this one level deeper: message.creator.mother
- but not more than that.