Join two classes data
Opened this issue · 2 comments
Hi all,
I have a two classes that i want to join.
The first class is the user and the second one is the articles. On the articles i have a pointer called "parent" that has the objectId of the user.
Now i want to get all the articles and the data of the user for each one.
The where pointer is not working for this situation only if i want to get specific user's articles.
$activityQuery = new parseQuery('Articles');
$activityQuery->whereInclude('_User');
$activityQuery->whereInQuery('parent','_User', array('where' => array(
'username' => array('$exists' => true)
)));
$result = $activityQuery->find();
With this code i can get all articles that are linked with users but with no user data (no user fields).
Any suggestions?
Hi i found the solution through mac os console with curl and i found how to do it.
I want to share my my findings because i've seen lot of confusion on the internet around this.
If you have the first table articles linked with user throught the pointer name "parent" then you must do the following
$Query = new parseQuery('Article');
$Query->orderBy('createdAt');
$Query->whereInQuery('parent','_User', array('where' => array('userType' => 1)));
$Query->whereInclude('parent');
- get the article
- sorted or not doesnt really matter
- then i use the where for the child class because the ->where looks on the first class that is called and not the join one. So i use whereInQuery to get all users that are registered with userType 1
- then finally to include all the fields from the user i include the pointer field and the api does everything for you
Good luck,
if you like to know more you can check (https://leanpub.com/building-web-applications-using-parse-rest-api) which has many topics covered ..