Google App Engine ndb等同于modelname_set(反向引用属性) [英] Google App Engine ndb equivalent for modelname_set (backreference property)
问题描述
在 modelname_set (后向引用属性) / ndb / overview> Google App Engine的NDB ?
在旧的DB中,Model实体具有将后向引用属性描述为:
返回引用属性的名称默认为modelname_set(模型类的名称以小写字母表示,_set添加到结尾),并且可以使用reference_name属性构造函数的collection_name参数进行调整。
我注意到这个属性似乎并不存在于NDB db.Model
实例中。
NDB是否与back-reference属性等价?
NDB中没有直接的后向参考属性,因为NDB没有完全使用与原始数据存储客户端相同的范例。您可以使用KeyProperty作为您的前向引用,然后使用查询来查找所有具有该KeyProperty设置的背景引用。 class Comment(ndb.Model)
source = ndb.KeyProperty()
qry = Comment.query()。filter(source = ndb.Key('Source','Sandy') )
Is there an equivalent for modelname_set
(a back-referenced property) in Google App Engine's NDB?
In the old DB a Model entity had described the back-reference property as:
The name of the back-reference property defaults to modelname_set (with the name of the model class in lowercase letters, and "_set" added to the end), and can be adjusted using the collection_name argument to the ReferenceProperty constructor.
I noticed this property does not seem to exist with NDB db.Model
instances.
Does NDB have an equivalent to the back-reference property?
There is no direct back-reference properties in NDB because NDB doesn't quite use the same paradigm as the original datastore client. You would use a KeyProperty for your forward reference and then use a query for everything that has that KeyProperty set for your back reference.
class Comment(ndb.Model)
source = ndb.KeyProperty()
qry = Comment.query().filter(source=ndb.Key('Source', 'Sandy'))
这篇关于Google App Engine ndb等同于modelname_set(反向引用属性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!