creating a compound or composite key on google app engine -


i have 2 models: car(ndb.model) , branch(ndb.model) each key method.

@classmethod def car_key(cls, company_name, car_registration_id):     if not (company_name.isalnum() , car_registration_id.isalnum()):         raise valueerror("company & car_registration_id must alphanumeric")     key_name = company_name + "-" + car_registration_id     return ndb.key("car", key_name) 

branch key:

@classmethod def branch_key(cls, company_name, branch_name):     if not (company_name.isalnum() , branch_name.isalnum()):         raise valueerror("company & branch names must alphanumeric")     key_name = company_name + "-" + branch_name     return ndb.key("branch", key_name) 

however i'm thinking bit ugly , not how you're supposed use keys.

(the car registration unique car 1 company may sell car company , cars move between branches).

since company may many cars or many branches, suppose don't want large entity groups because can write entity group once per second.

how should define keys?

e.g. i'm considering car_key = ndb.key("car", car_reg_id, "company", company_name) since it's unlikely car have many companies entity group wont big.

however i'm not sure branch key since many companies may have same branch name, , many branches may have same company.

you've rightly identified ancestor relationships in gae should not based on logical structure of data.

they need based on transactional behavior of application. ancestors make life difficult. example, once use compound key, won't able fetch entity key unless happen know elements of key. if knew car id, wouldn't able fetch without knowing other component.

consider queries need have strong consistency for. if happen need strong consistency when querying cars in given branch, should consider using ancestor.

consider operations need done in transaction, that's reason using entity group.

keep in mind also, might not need entity group @ (probably answer situation).

or, on flip side, might need entity group might not fit logical conceptual model, ancestor might entity exists purely exists because need ancestor transaction.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -