Google App Engine:在引用属性上调用.key().id()会触发该实体的获取吗?

Pwn*_*fex 3 google-app-engine

如果我有一个带引用属性的对象,那么在引用属性上调用.key()或.key().id()方法会导致从数据存储中检索它吗?或者我可以从没有触发请求的那些人那里获得价值吗?

class MyObject(db.Model):
    reference = db.ReferenceProperty()

myObj = MyObject( reference = myOtherObject )
myObj.put()

# Will this retrieve the key without doing a get for the object?
temp1 = myObj.reference.key()

# What about this?
temp2 = myObj.reference.key().id()
Run Code Online (Sandbox Code Playgroud)

mor*_*aes 10

从模型实例访问属性将取消引用它(它将被获取):

# This will retrieve the key after doing a get for the object.
temp1 = myObj.reference.key()
Run Code Online (Sandbox Code Playgroud)

要在不取消引用的情况下获取密钥,请使用:

# This will retrieve the key without doing a get for the object.
temp1 = MyObject.reference.get_value_for_datastore(myObj)

# Then you get the id...
temp2 = temp1.id()
Run Code Online (Sandbox Code Playgroud)