tutchmedia
tutchmedia

Reputation: 139

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

Upvotes: 0

Views: 499

Answers (2)

tutchmedia
tutchmedia

Reputation: 139

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.

Upvotes: 0

shayegh
shayegh

Reputation: 322

use getRelation() on relation columns, not get()

$user = ParseUser::getCurrentUser();
$relation = $user->getRelation("likes");
$query = $relation->getQuery();
$query->equalTo("title", "I'm Hungry");
$postsLiked = $query->find();

http://docs.parseplatform.org/php/guide/#many-to-many-relationships

Upvotes: 1

Related Questions