googledatastore做延迟加载吗?

2024-10-01 04:49:08 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我有一个包含订单列表的Customer对象,使用数据库参考属性在

过了一段时间,我可能会有大量的订单在那里,如果我拉客户对象,我会有危险拉全套订单吗?在


Tags: 对象订单数据库列表属性customer我会拉客户
1条回答
网友
1楼 · 发布于 2024-10-01 04:49:08

是的,数据库参考属性字段被延迟加载。来自the docs

ReferenceProperty automatically references and dereferences model instances as property values: A model instance can be assigned to a ReferenceProperty directly, and its key will be used. The ReferenceProperty value can be used as if it were a model instance, and the datastore entity will be fetched and the model instance created when it is first used in this way. Untouched reference properties do not query for unneeded data.

例如:

# 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

相关问题 更多 >