2013-03-11 67 views
2

试图找出将Webapp2 Auth用户对象作为参考存储在谷歌应用程序引擎ndb域实体中的最佳做法。在Google App Engine中存储用户对象

3种方式我能想到这样做

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

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

在那里我会存储用户ID从webapp2的用户对象的像

user.get_id() 

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

在那里我会存储用户的密钥从webapp2的用户对象像

user.key 

我不知道什么是最好的做法吗?特别是存储user_id和key有什么优势?假设UserProperty是旧的做事方式?

回答

3

避免UserProperty,改为存储ID。

直接从源...

# 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. 
    """ 
+0

是ID比键更好,因为他们也有KeyProperty(允许指定特定类型)本来以为存储密钥更好? – dboyd68 2013-03-13 08:02:30

+1

该ID是唯一标识该用户的密钥,该密钥可以是特定于实现的。 – jdiaz5513 2013-03-14 00:36:10

相关问题