Google App Engine ndb equivalent for modelname_set (backreference property)

China☆狼群 提交于 2019-11-27 16:21:12

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/9917569/google-app-engine-ndb-equivalent-for-modelname-set-backreference-property

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