views:

114

answers:

2

On Google App Engine in Python, I have a Visit entity that has a parent of Patient. A Patient may have multiple visits.

I need to set the most_recent_visit (and some auxiliary visit data) somewhere for later querying, probably in another child entity that Brett Slatkin might call a "relationship index entity."

I wish to do so in a bulk style as follows:

1. get 100 Patient keys
2. get all Visits that have any of the Patients from 1 as an ancestor
3. go through the Visits and get the latest for each Patient

Is there any way to perform step 2 in a bulk get?

I know there is a way to bulk get entities from a list of keys, and there is a way to match a single entity by its ancestor.

A: 

There's no way in the datastore to to the kind of query you're looking for; it's a join, which isn't supported. Step 2 is going to require 100 queries.

You could store a list of Visit keys in each Patient entity, and then be able to do a simple bulk get all of these entities based on their keys.

Wooble
A: 

Why not maintain a list of patient visit keys on the patient object? You will already know the last visit because it will be the last key added to the list.

My NF detector is going off like crazy which makes me think this is the right solution for the datastore.

Flory