如何按用户在 Google App Engine 中搜索实体?
我正在尝试查找与当前用户相关的用户实体,但在用户存储在数据库中后我似乎无法找到该用户。
当我第一次创建用户时,我进行的调用如下所示:
newPlayer = model.Player(parent=model.user_key(), user=users.GetCurrentUser(), publicName = nickname)
newPlayer.put()
其中 model.Player 是我要查找的元素,而 model.user_key() 获取全局祖先用户密钥。
当我去查找它们时,我会执行以下操作:
model.Player.all().filter('user =', usr).ancestor(user_key()).fetch(1)
模型 Player 类如下所示:
class Player(db.Model):
user = db.UserProperty
publicName = db.StringProperty()
每次都会返回一个空列表。我在这里做错了什么?我现在开始质疑决定论......
I am attempting to lookup a user entity that is related to the current user, and I do not seem to be able to find the user after they get stored in the database.
When I am creating the user for the first time, the call I make looks like the following:
newPlayer = model.Player(parent=model.user_key(), user=users.GetCurrentUser(), publicName = nickname)
newPlayer.put()
Where model.Player is the element I am trying to lookup, and model.user_key() gets a global ancestor user key.
When I go to look them up, I do the following:
model.Player.all().filter('user =', usr).ancestor(user_key()).fetch(1)
The model Player class looks like this:
class Player(db.Model):
user = db.UserProperty
publicName = db.StringProperty()
This returns an empty list every time. What am I doing wrong here? I am starting to question determinism at this point...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
User 不是数据存储中的类,因此您不能将player 作为它的子级。这应该有效:
注意:get_current_user() 不是 GetCurrentUser() 来源
User is not a class in datastore, so you can't make player a child of it. This should work:
Note: is get_current_user() not GetCurrentUser() source