分析PHP SDK-返回NULL或未定义值的记录


Parse PHP SDK - return records with NULL or undefined value

我通过Parse PHP SDK存储了一些记录。在字段中有一个日期字段,该字段是用未定义的值初始化的。

在旅途中,这个值可能会更改为真实日期或空值,以防我设置了一个日期,然后想"取消设置"它。我正在做的是将其设置为空。

问题是,当我想过滤设置的日期和所有其他日期时(在我的情况下,未定义的值和空值都应该相同,即"未设置"),我会尝试类似于以下的查询过滤器:

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

奇怪的是,它只返回未定义的值,而不是NULL值。

另一方面,当我使用时

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

所需的记录都返回得很好。

知道如何同时获得null和未定义的值吗?

提前谢谢。

你是对的,它似乎不适用于PHP库。同样的事情也适用于Javascript库。

不过,您可以通过排除非null(或未定义)的值来实现您想要的。这里有一个例子:

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();

您可以使用ParseQuery类的existsdoesNotExist方法筛选具有空字段的查询。

$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.