How do you NOT automatically dereference a db.ReferenceProperty in Google App Engine?

一曲冷凌霜 提交于 2019-12-03 21:44:14

As the docs say,

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.

so you're fine as long as you don't touch it, but if you do though it, e.g. with an .id() call as you show, "the datastore entity will be fetched", the docs say. More docs are here, but they don't show a way to magically get the id without fetching, either.

I have not tried, but you might be able to use the get_value_for_datastore of the property to get "the Python-native value of the property" which I believe is indeed a Key -- whose id() method should be callable without datastore fetches. Have you tried that?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!