对应于 modelname_set(反向引用属性)的 Google App Engine ndb [英] Google App Engine ndb equivalent for modelname_set (backreference property)

查看:32
本文介绍了对应于 modelname_set(反向引用属性)的 Google App Engine ndb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中是否有与 modelname_set(反向引用的属性)等效的内容Google App Engine 的 NDB?

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:

反向引用属性的名称默认为modelname_set(模型类的名称为小写字母,并在末尾添加_set"),并且可以使用ReferenceProperty构造函数的collection_name参数进行调整.

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.

我注意到 NDB db.Model 实例似乎不存在此属性.

I noticed this property does not seem to exist with NDB db.Model instances.

NDB 是否具有与反向引用属性等效的属性?

Does NDB have an equivalent to the back-reference property?

推荐答案

在 NDB 中没有直接的反向引用属性,因为 NDB 与原始数据存储客户端使用的范例并不完全相同.您可以使用 KeyProperty 作为前向引用,然后对所有设置了该 KeyProperty 的内容作为后向引用使用查询.

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'))

这篇关于对应于 modelname_set(反向引用属性)的 Google App Engine ndb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆