Google App Engine NDB祖先查询不起作用 [英] Google App Engine NDB ancestor query not working

查看:82
本文介绍了Google App Engine NDB祖先查询不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行以下查询:

  query = Comment.query(ancestor = userKey,ndb.OR (Comment.modifiedDate> lastSyncDate,Comment.activityDate> lastSyncDate))

1等号=)是文档说明我们应该拥有它的方式,但当我只有1个等号(构建错误)时,我的应用程序不运行。如果我使用两个等号,比如 ancestor == userKey ,那么应用程序将运行,但是我得到一个 NameError:全局名称'ancestor'不是定义。什么给出了?



我也试过这个查询的另一个变体,但是同样的问题发生了:



<$ p $ (ndb.AND(ancestor == userKey,ndb.OR(Comment.modifiedDate> lastSyncDate,Comment.activityDate> lastSyncDate)))
query =您需要将祖先放入


解决方案 >关键字之后方法位置参数:

  query = Comment.query(
ndb .OR(Comment.modifiedDate> lastSyncDate,Comment.activityDate> lastSyncDate),
ancestor = userKey)

或者,可以显式使用 filters 关键字,或者使用 .filter()方法:

  query = Comment.query(
ancestor = userKey,
filters = ndb.OR(Comment.modifiedDate> ; lastSyncDate,Comment.activityDate> lastSyncDate))

  query = Comment.query(ancestor = userKey).filter(ndb.OR(Comment.modifiedDate> lastSyncDate,Comment.activityDate> lastSyncDate))


I'm trying to execute the following query:

query = Comment.query(ancestor = userKey, ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))

The 1 equal sign (=) is how the docs said we should have it, but my app doesn't run when I have just 1 equal sign (build error). If I use two equal sign, like ancestor == userKey, then the app runs, but I get a NameError: global name 'ancestor' is not defined. What gives?

I also tried another variant of this query, but the same exact problem occurs:

query = Comment.query(ndb.AND(ancestor == userKey, ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate)))

解决方案

You need to put the ancestor keyword after the method positional parameters:

query = Comment.query(
    ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate),
    ancestor=userKey)

Alternatively, use the filters keyword explicitly, or use the .filter() method:

query = Comment.query(
    ancestor=userKey,
    filters=ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))

or

query = Comment.query(ancestor=userKey).filter(ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))

这篇关于Google App Engine NDB祖先查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆