0

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.

OTG
  • 51
  • 4

1 Answers1

0

You can only use matchesQuery for pointers. For your case, you have to use matchesKeyInQuery.

$query->matchesKeyInQuery("phostId", "objectId", $innerQuery);

Replace objectId with column name of ID that you want to compare with.

Hope this helps :)

Ye Min Htut
  • 2,904
  • 15
  • 28
  • Thanks Ye Min Htut. I am still having a hard time seeing where I combine the OR query into the overall query. – OTG Dec 20 '16 at 13:46
  • Thanks Ye Min Htut. I am still having a hard time seeing where I combine the OR query into the overall query. in my code above I have 5 different queries. 1) for my pointer **$innerQuery** 2) for my OR query **$endDate and $isPerm** 1) that is the actual OR query **$mainQuery** 1) and lastly the final query or parent where I hope to see the results of all of the above queries it is named **$query** It seems like I should be able to nest the OR query somewhere inside the parent query. – OTG Dec 20 '16 at 13:54
  • Can you check your date object or edit you answer with how you initialize ur date object? It seems something is wrong in ur date object. – Ye Min Htut Dec 20 '16 at 15:17