I'm moving away from the REST API in my PHP code and converting to the php sdk for parse.
I am having trouble converting this REST API query to the proper syntax for the parse php-sdk and could use a few pointers.
This is the working REST API query.
where=
{"phostId":
{"__type":"Pointer","className":"Hosts","objectId":"'.$hostObjId.'"},
"isCompany":false,
"expunged":{"$nin":[true]},
"$or":[
{"endDate":
{"$gte":
{
"__type":"Date",
"iso":"'.$now.'"
}
}
},
{"isPerm":true}
]
}
&keys=pvisitorId,company,isPerm,startDate,endDate,name
&include=pvisitorId&order=-name';
I can query based on the Pointer with no issue but I am not able to figure out how to work in the OR clause.
This is what I have so far.
//Query the pointer for an object id matching our user session id
$innerQuery = new ParseQuery("Hosts");
$innerQuery->equalTo("objectId",$_SESSION['host_object_id'] );
//Building two queries used for the OR condition
$endDate = new ParseQuery("Authorizations");
$endDate->greaterThan("endDate", $date);
$isPerm = new ParseQuery("Authorizations");
$isPerm->equalTo("isPerm", True);
//create primary query
$query = new ParseQuery("Authorizations");
//set filters
$query->equalTo("isCompany",False);
$query->notEqualTo("expunged",True);
////This is what I am trying to add to $query just not sure how to do it.
$mainQuery = ParseQuery::orQueries([$endDate, $isPerm]);
$results1 = $mainQuery->find();
//Sort, Limit, add InnerQuery
$query->addDescending("name");
$query->limit(1);
$query->matchesQuery("phostId", $innerQuery);
// All results:
$results = $query->find();
Thanks in advance for any help or pointers on what I am missing.
You can only use
matchesQuery
for pointers. For your case, you have to usematchesKeyInQuery
.Replace
objectId
with column name of ID that you want to compare with.Hope this helps :)