I read the engine in a Google application and prepare a sample to better understand it.
In a nutshell, the user can record an entry for each day of the month, like a calendar. And the user can view the entries monthly. Thus, no more than 30 um at a time.
I originally used db , and the one-to-many relationship was straightforward.
But as soon as I stumbled upon ndb , I realized that there are two ways to model a one-to-many relationship.
1) The structured property seems to act as a repetitive property in the User model. Does this mean that if I get one user, I would automatically receive all the entries that she entered? (like a whole year) It's not very effective, right? I assume that the advantage is that you get all the associated data in a single read operation.
from google.appengine.ext import ndb class User(UserMixin, ndb.Model): email = ndb.StringProperty(required = True) password_hash = ndb.TextProperty(required = True) record = ndb.StructuredProperty(Record, repeated=True) class Record(ndb.Model): notes = ndb.TextProperty()
2) As an alternative, I could use a perhaps more classic way:
class User(UserMixin, ndb.Model): email = ndb.StringProperty(required = True) password_hash = ndb.TextProperty(required = True) class Record(ndb.Model): user = ndb.KeyProperty(kind=User) notes = ndb.TextProperty()
Which method is better in my use case?
source share