KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
ReferenceProperty was very helpful in handling references between two modules. Fox example: class UserProf(db.Model): name = db.StringProperty(required=True) class Team(db.Model): manager_name = db.ReferenceProperty(UserProf, collection_name='teams') name = db.StringProperty(required=True) To get 'manager_name' with team instance, we use team_ins.manager_name. To get 'teams' which are managed by particular user instance, we use user_instance.teams and iterate over. Doesn't it look easy and understandable? In doing same thing using NDB, we have to modify db.ReferenceProperty(UserProf, collection_name='teams') --> ndb.KeyProperty(kind=UserProf) team_ins.manager_name.get() would give you manager name To get all team which are manger by particular user, we have to do for team in Team.query(Team.manager_name == user_ins.key): print "team name:", team.name As you can see handling these kind of scenarios looks easier and readable in db than ndb. What is the reason for removing ReferenceProperty in ndb? Even db's query user_instance.teams would have doing the same thing as it is done in ndb's for loop. But in ndb, we are explicitly mentioning using for loop. What is happening behind the scenes when we do user_instance.teams? Thanks in advance..
Tags (comma-separated)
Save Edits
Cancel