Ron*_*han 2 python google-app-engine google-cloud-datastore
如果我有一个带有订单列表的Customer对象,则使用db.ReferenceProperty声明
过了一段时间我可能会在那里有大量的订单,如果我拉出客户对象,我是否会有拉动整套订单的危险?
是的,db.ReferenceProperty字段是懒惰加载的.来自文档:
ReferenceProperty自动引用和取消引用模型实例作为属性值:可以直接将模型实例分配给ReferenceProperty,并使用其键.ReferenceProperty值可以像使用模型实例一样使用,并且将获取数据存储区实体,并在以这种方式首次使用时创建模型实例.未触及的引用属性不会查询不需要的数据.
所以,例如:
# Any reference properties not loaded yet
customer = Customer.get_by_id(1)
print customer.name
print customer.address
# Assuming customer.order is a ReferenceProperty, now is when it
# would be loaded from the datastore.
print customer.order.created_at
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
502 次 |
| 最近记录: |