3

I have some records stored through Parse PHP SDK. Among the fields there is a Date field which is initialized with an undefined value.

On the go this value may change either to a real date or a null value, in case I set a date and then want to "unset" it. What I am doing is setting it as null.

The problem is that when I want to filter the set dates and all the others (in my case both undefined and null values should be the same, i.e. "unset") I try a query filter similar to the following:

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

The weird thing about it is that it only returns the undefined values, not the NULL ones.

On the other hand when I use

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

the desired records are all returned just fine.

Any idea how to accomplish getting both null and undefined values?

Thanks in advance.

2 Answers 2

2

You are correct, it doesn't seem to work with the PHP library. The same thing works fine with the Javascript library.

You can accomplish what you want though by excluding the values that are not null (or undefined). Here is 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();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks abinop! Although this is isn't the optimal way to accomplish what I want it definitely works in my case. I hope parse.com team will take care of this in a future release.
-1

You can filter queries with null fields with exists and doesNotExist methods of 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 Comment

This filters only filters fields with undefined value, not null fields. In parse you have null AND undefined values. The query should be "doesNotExists or equals null", but I have no clue how to ad that "or".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.