views:

38

answers:

1

I have models set up as the following:

class Day(db.Model):
    date = db.DateProperty()
    total = db.FloatProperty()

class Event(db.Model):
    desc = db.StringProperty()
    amount = db.FloatProperty()

The hierarchy is as such: User > Day > Event (Users have Days. Days have Events.)

When a user logs in I want to select their days (for a range by date lets say) and then for each day I want to get their Events. Let's just say these are displayed in a list for now.

Should I use the parent property to create an explicit entity group? Or should I add a reference property on Day for a User, and add a reference property on Event for a Day?

What are the pros and cons of each method? Performance considerations? Scalability considerations? And also, how would I query for this in the best possible way.

Thanks!

A: 

If you need to transactionally update Day and Entity models together (eg, that 'total' field needs updating with each event), use entity groups. Otherwise, use reference properties.

To most efficiently select all the events in a date range, your best option would be to denormalize somewhat, and put a 'date' property on the event, as well. Then you can do a query on all events for the given user, within the given range, and fetch Day entities from those, if you need them.

Nick Johnson