I'm stuck trying to implement a data model for an app to be deployed on AppEngine.
Here's an example of the model:
EntityName
id: 1
author: 'me'
description: 'whatever'
datetime: 2011 etc.
events: [
{location: [1,2], phase: ['A', 'B']},
{location: [3,4], phase: ['C', 'B']},
... more events ...
]
Explanation:
EntityName
has a few attributes, and manyevents
- each
event
has a list of numbers (itslocation
) and a list of strings (phase
)
How can this model be implemented in AppEngine? The data only needs to be searchable by id
, author
, datetime
, and description
.
What I've tried to figure out how to do (still going through the docs) (sticking point in italics):
- one table,
EntityName
, withevents
as aListProperty
this would require nested lists in one table ... not sure if that's possible - two tables,
EntityName
andEvent
needs a join, which I understand isn't directly possible
Here's an alternative that only uses one model (i.e., Nick's idea):
Sample output:
Since order is generally preserved in List and StringList properties, your locations and phases for an event can be matched up -- i.e., they have the same index in the two lists.
With one model you have to do a little more work splitting out each entry in the list, but you save on datastore reads and writes, since you only have one entity.
These aren't tables, exactly, but I think this should work for you
Then...
See the documentation for details. You don't need to "do a join" because this isn't a SQL database. For your convenience, collection_name will create an iterator on the referenced side of a one-to-many relationship.