google app engine - When do you store ids and when do you store keys in gae datastore? -
suppose datastore model looks this:
@entity public class user { @id private long id; @index private string email; private long dateofbirth; // more fields... } @entity public class topic { @id private long id; private string topictitle; private long date; } @entity public class comment { @id private long id; @parent private key<topic> topickey; private long commenterid; private string text; private long date; }
where entity comment has parent entity topic. know 1 should store keys when specifying @parent
such did in comment entity, should 1 store key of commenterid
? or storing long
id of user enough?
just wondering best practice storing references other entities when not parents - should store id , generate key later or store key entity. there reason why might 1 on other?
edit: since using cloud endpoints, responses appengine project json. parameterized type of key not allowed in client libs. me, id
can work , key<?>
can work. note should return websafe version of client using:
mykey.getstring();
typically there no reason store key reference. keys take more space - both in datastore, , in objects transfer , client.
using key may necessary if same entity kind can either or child of entity. technically possible, , data models can use approach, although rare use case.
nb: use id of parent in objects - same reason (less space). in datastore entities parent id can extracted child entity key. use low-level datastore api, - need check how correctly annotate child-parent relationship in library use.
Comments
Post a Comment