Storing User Objects in Google App Engine

筅森魡賤 提交于 2019-12-11 01:57:24

问题


Trying to figure out the best practice when storing Webapp2 Auth user objects as a reference in a google app engine ndb domain entity.

The 3 ways I can think to do it

class MyEntity(ndb.Model):
  users = ndb.UserProperty(repeated=True)

or

class MyEntity(ndb.Model):
  users = ndb.StringProperty(repeated=True)

where I would store user id's from the webapp2 User object like

user.get_id()

or

class MyEntity(ndb.Model):
  users = ndb.KeyProperty(repeated=True)

where I would store user key from the webapp2 User object like

user.key

I am not sure what is the best practice here? In particular is there any advantage to storing user_id vs key? Assuming UserProperty is the old way of doing things?


回答1:


Avoid UserProperty, store the ID instead.

Straight from the source...

# google/appengine/ext/ndb/model.py:1711

class UserProperty(Property):
  """A Property whose value is a User object.

  Note: this exists for backwards compatibility with existing
  datastore schemas only; we do not recommend storing User objects
  directly in the datastore, but instead recommend storing the
  user.user_id() value.
  """


来源:https://stackoverflow.com/questions/15345502/storing-user-objects-in-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!