2013-03-11 1 views
2

Google App Engine ndb 도메인 엔터티에 Webapp2 인증 사용자 개체를 참조로 저장하는 것이 가장 좋습니다. 내가 생각할 수있는Google App Engine에 사용자 개체 저장

3 가지 방법이해야 할 일이

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

또는

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

내가

user.get_id() 

또는

같은 사용자 ID에게 webapp2 사용자 개체에서의 저장 것

class MyEntity(ndb.Model): 
    users = ndb.KeyProperty(repeated=True) 
내가 가장 좋은 방법은 여기에 무엇을 나는 확실하지 않다

user.key 

같은 webapp2 사용자 개체에서 사용자 키를 저장하는 것

? 특히 user_id와 key를 저장하면 어떤 이점이 있습니까? UserProperty가 일을하는 오래된 방법이라고 가정합니다.

답변

3

UserProperty를 피하고 대신 ID를 저장하십시오. 그들은 또한의 KeyProperty 더 키를 저장하는 생각 했을까 (특정 유형을 지정할 수) 때문에 스트레이트 소스에서

...

# 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를 더 키가 아닌가요? – dboyd68

+1

ID는 사용자를 고유하게 식별하는 것으로 Key는 구현에 따라 다를 수 있습니다. – jdiaz5513