python - Can you help me understand the nbd Key Class Documentation or rather ancestor relationship? -
i trying wrap head 'round gae datastore, not understand documentation key class / or maybe ancestor relationships in general not grasp. think want multiple ancestors.
example: wanted model our school's annual sponsored run charity; school kids run rounds around track , relatives (=sponsors) donate charity each round completed.
in mind, create following kinds:
- profile (can both runner , sponsor)
- run (defines (cf. profile) runs charity, rounds completed)
- sponsorship (defines (cf. profile) donates how run, whether donation has been made)
i've learned datastore nosql, non-relational database, haven't grasped it. questions are:
a. creating entity "sponsorship" best way in datastore? model has-a relationship (every run has sponsors) - since want track amount sponsored, whether sponsor paid , maybe more seems inappropriate
b. i'd query sponsorhips made single person , sponsorships belonging run. so, feel, appropriate:
profile --is ancestor of--> run profile --is ancestor of--> sponsorship run --is ancestor of--> sponsorship
is sensible? can see constructor key takes several kinds in ancestor order arguments. designed case? "run" , "profile" @ same "level" (i.e. mum&dad ancestors not father&grandfather) - constructor in python?
the primary way of establishing relationships between entities via key properties in entity model. no ancestry needed.
for example:
class profile(ndb.model): name = ndb.stringproperty() class run(ndb.model): runner = ndb.keyproperty(kind='profile') rounds = ndb.integerproperty() sponsorship = ndb.keyproperty(kind='sponsorship') class sponsorship(ndb.model): run = ndb.keyproperty(kind='run') donor = ndb.keyproperty(kind='profile') done = ndb.booleanproperty()
the ancestry places entities inside same entity group (which can quite limiting!) while enforcing additional relationships on top of ones established model. see transactions , entity groups , maybe contention problems in google app engine.
Comments
Post a Comment