Parse PHP SDK - Return records with NULL or undefined

I have entries stored in the Parse PHP SDK. Among the fields is the Date field, which is initialized to undefined.

On the way, this value can change to either the real date, or zero if I set the date and then want to "undo" it. What I am doing is setting it to null.

The problem is that when I want to filter the dates set and all the others (in my case both undefined and zero values ​​should be the same, that is, "unset") I will try a query filter like the following:

$query->equalTo("mydatefield", NULL);

      

The weird thing is that it only returns undefined values ​​and not NULL.

On the other hand, when I use

$query->notEqualTo("mydatefield", NULL);

      

all required records are returned.

Any idea how to achieve getting null and undefined values?

Thanks in advance.

+3


source to share


2 answers


You are right, it doesn't work with PHP library. The same works great with the Javascript library.

You can accomplish what you want, but excluding values ​​that are not null (or undefined). Here's an example:



use Parse\ParseQuery;       

//fetch objectIds of all data that is not null
$query = new ParseQuery("tabledata");
$query = $query -> notEqualTo("mydatefield", null);
$results = $query -> find();
$keys = array();

for ($i=0; $i<count($results); $i++){
    array_push($keys, $results[$i]-> getObjectId());
}

//now fetch all records but the records with the null column
$query2 = new ParseQuery("tabledata");
$query2 = $query2 -> notContainedIn("objectId", $keys);
$results2 = $query2 -> find();

      

+2


source


You can filter queries with null fields using methods exists

and doesNotExist

the ParseQuery class.



$query->exists("mydatefield");   // returns rows that do not have null value for mydatefield key.

$query->doesNotExist("mydatefield");   // returns rows that have null value for mydatefield key.

      

-1


source







All Articles