Skip to content
This repository has been archived by the owner on Feb 25, 2018. It is now read-only.

Join two classes data #152

Open
ghost opened this issue May 28, 2014 · 2 comments
Open

Join two classes data #152

ghost opened this issue May 28, 2014 · 2 comments

Comments

@ghost
Copy link

ghost commented May 28, 2014

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?

@ghost
Copy link
Author

ghost commented May 29, 2014

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');

  1. get the article
  2. sorted or not doesnt really matter
  3. 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
  4. then finally to include all the fields from the user i include the pointer field and the api does everything for you

Good luck,

@zaherg
Copy link

zaherg commented May 29, 2014

if you like to know more you can check (https://leanpub.com/building-web-applications-using-parse-rest-api) which has many topics covered ..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant