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'))
来源:https://stackoverflow.com/questions/9917569/google-app-engine-ndb-equivalent-for-modelname-set-backreference-property