I am having trouble understanding how to structure a tree of ancestors with several decades. Suppose I have a model like this (each object has Long id):
User
-Post
-Comment
Where Commentis the grandson User.
Which is really annoying, CommentI need to insert; I need to generate a key Post. And to generate the key, PostI also need to know the identifier User:
Key<Post> postKey = Key.create(Key.create(User.class, userId), Post.class, postId);
This is a problem for me, because when trying to insert a comment into the data store, I need to also pass to userId and postId only to generate the key Post.
Similarly, it is annoying to try to get one post, because I need to pass both userId and postId to generate the key.
I am looking for the best way to structure my model and API methods without having to pass all these ancestor identifiers to my methods . I considered saving websafeKey in each Post and Comment object as a property similar to this:
String websafeKey = Key.create(Key.create(User.class, userId), Post.class, postId).getString();
Key<Post> key = Key.create(websafeKey);
Then I could use a key for each post and comment (and other children of these entities) right there in Entity. Then, probably, I would not have to pass all these ancestor identifiers to my API methods all the time.
Not sure if this is a good idea.