Search code examples
phpparse-platform

Parse PHP - Query on Relation class


I'm currently using the PHP library of Parse SDK and i would like to do an equalTo query on the relation object of a row.

Basically, get all the Lines where relation class LineData column 'status' = 1.

Does anyone have any idea on how to achieve this? I can't find anything in the official docs or a google search.

$query = new ParseQuery("Lines");
$innerQuery = $query->get("LineData")->getQuery()->find();

$innerQuery->equalTo("status", ['__type' => "Pointer", 'className'=> "States", 'objectId' => "XvGh5HkSAw"]);
$results = $innerQuery->find();
return $results;

Any help would be greatly appreciated. Thanks


Solution

  • I managed to figure this out myself. Seems we have to do a a query on the child class and then match that query with the parent class.

    $innerQuery = new ParseQuery("LineData");
    $innerQuery->equalTo("Status", ['__type' => "Pointer", 'className'=> "States", 'objectId' => "XvGh5HkSAw"]);
    
    $query = new ParseQuery("Lines");
    $query->matchesQuery("InnerLine", $innerQuery);
    $all = $query->find();
    

    Hope it helps anyone.