My adventures with entity groups continue after a slightly embarrassing beginning (see Under some circumstances an App Engine get_by_key_name
call using an existing key_name returns None).
I now see that I can't do a normal get_by_key_name
call over a list of entities for child entities that have more than one parent entity. As the Model docs say,
Multiple entities requested by one (
get_by_key_name
) call must all have the same parent.
I've gotten into the habit of doing something like the following:
# Model just has the basic properties
entities = Model.get_by_key_name(key_names)
# ContentModel has all the text and blob properties for Model
content_entities = ContentModel.get_by_key_name(content_key_names)
for entity, content_entity in zip(entities, content_entities):
# do some stuff
Now that ContentModel entities are children of Model entities, this won't work because of the single-parent requirement.
An easy way to enable the above scenario with entity groups is to be able to pass a list of parents to a get_by_key_name
call, but I'm guessing that there's a good reason why this isn't currently possible. I'm wondering if this is a hard rule (as in there is absolutely no way such a call could ever work) or if perhaps the db module could be modified so that this type of call would work, even if it meant a greater CPU expense.
I'd also really like to see how others accomplish this sort of task. I can think of a bunch of ways of handling it, like using GQL queries, but none I can think of approach the performance of a get_by_key_name
call.