不平等查询不起作用 ndb
Inequality query not working ndb
Session.sessionType
是一个 StringProperty(repeated=True)
当我执行此查询时:
sessions_no_type = Session.query(Session.sessionType == request.sessionType)
一切似乎都在工作,我只得到那些有request.sessionType
的会话
但是当我尝试时:
sessions_no_type = Session.query(Session.sessionType != request.sessionType)
我恢复了所有会话(不管 request.sessionType
)
这可能是什么问题?即使文档也有类似的示例,但它对我不起作用。
尝试此版本时也是如此:
filter = ndb.query.FilterNode("sessionType", "!=", request.sessionType)
当测试是否相等时,它 returns 一切正确,但不相等的情况只会消除具有一个 sessionType 等于传递的(请求)sessionType
的 Session 对象
The != and IN Operations 的文档说:
The != (not-equal) and IN (membership) operations are implemented by
combining other filters using the OR operation. The first of these,
property != value
is implemented as
(property < value) OR (property > value)
因为您使用的是重复的 StringProperty,如果 sessionType
中的任何字符串不等于 request.sessionType
,则该实体将在查询中返回。
Session.sessionType
是一个 StringProperty(repeated=True)
当我执行此查询时:
sessions_no_type = Session.query(Session.sessionType == request.sessionType)
一切似乎都在工作,我只得到那些有request.sessionType
的会话
但是当我尝试时:
sessions_no_type = Session.query(Session.sessionType != request.sessionType)
我恢复了所有会话(不管 request.sessionType
)
这可能是什么问题?即使文档也有类似的示例,但它对我不起作用。
尝试此版本时也是如此:
filter = ndb.query.FilterNode("sessionType", "!=", request.sessionType)
当测试是否相等时,它 returns 一切正确,但不相等的情况只会消除具有一个 sessionType 等于传递的(请求)sessionType
The != and IN Operations 的文档说:
The != (not-equal) and IN (membership) operations are implemented by combining other filters using the OR operation. The first of these,
property != value
is implemented as
(property < value) OR (property > value)
因为您使用的是重复的 StringProperty,如果 sessionType
中的任何字符串不等于 request.sessionType
,则该实体将在查询中返回。