Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine ndb equivalent for modelname_set (backreference property)

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?

like image 268
Brian M. Hunt Avatar asked Mar 29 '12 00:03

Brian M. Hunt


1 Answers

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'))
like image 131
Michael Robellard Avatar answered Sep 29 '22 23:09

Michael Robellard