【问题标题】:Google App Engine NDB ancestor query not workingGoogle App Engine NDB 祖先查询不起作用
【发布时间】:2012-09-04 15:49:09
【问题描述】:

我正在尝试执行以下查询:

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

1 等号 (=) 是 docs 所说的我们应该拥有它,但是当我只有 1 个等号时我的应用程序无法运行(构建错误)。如果我使用两个等号,例如ancestor == userKey,则应用程序会运行,但我会得到NameError: global name 'ancestor' is not defined。什么给了?

我也尝试了这个查询的另一种变体,但出现了同样的问题:

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

【问题讨论】:

  • @MartijnPieters 很好,我正在使用 textmate,然后按 cmd+r 运行,它只是显示错误,箭头指向第一个 > 符号。

标签: python google-app-engine


【解决方案1】:

你需要把ancestor关键字放在方法的位置参数之后:

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

【讨论】:

  • 你看起来像是把祖先放在了成功之后..很好的赶上
  • @mohabitar:很高兴它有帮助;你的意思是接受答案吗? :-P
  • 啊,是的,我必须向回答者提供他们的每日积分剂量,以免他们感到或退出;)
  • @mohabitar: 与 Jon Skeet 正面交锋(我知道这是徒劳的)...谢谢!
猜你喜欢
  • 2013-12-21
  • 1970-01-01
  • 1970-01-01
  • 2015-06-27
  • 2013-06-16
  • 1970-01-01
  • 1970-01-01
  • 2013-01-02
  • 1970-01-01
相关资源
最近更新 更多