当前位置: 动力学知识库 > 问答 > 编程问答 >

google app engine - GAE ndb query on user object

问题描述:

for car in Car.query().fetch():

print car.owner == users.get_current_user()

This prints True for all cars owned by the current user, as expected.

for car in Car.query(Car.owner == users.get_current_user()).fetch():

print car

While the current user owns several cars, this returns no results. Why?

网友答案:

Storing User objects in the Datastore is fraught with problems; the failing query is just one example (and no, sorry, I don't know why exactly it fails in your case).

You are much better off storing either just the "user ID" (i.e. users.get_current_user().user_id(), a string) or the email address -- depending on what you think should happen if a user changes the email address associated with their Google (GMail) Account. The user_id remains the same, the email address (obviously) changes.

网友答案:

I've added new cars owned by me and the query is picking those up as expected. This does not answer the technical problem (that is, I still don't understand why the query didn't work) - but it does solve my practical one.

分享给朋友:
您可能感兴趣的文章:
随机阅读: