django-nonrel/djangoappengine — Issue #18: References storage
Author: wrwrwr
Created: 2012-01-25 08:39:59+00:00
State: open

Consider a simplistic blob-post example:

```python
class Blog(models.Model):
pass

class Post(models.Model):
blog = models.ForeignKey(Blog)
```

If you store a post and look into the datastore you'll notice that a plain integer is stored for the "blog(_id)" field. However, GAE also has a db.Key data type that could be stored. There are some potential advantages of storing keys rather than integers / strings:

* better reflects your data (for example the datastore itself will know that a key refers to an entity that has been deleted -- consider it were to implement cascade deletes at some point);
* lets tools other than Django see the data structure (for example you could click and follow references in GAE admin console);
* this is what GAE uses for its ReferenceProperties: http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#ReferenceProperty
* it might (or may not) allow some optimizations (e.g. avoiding key creation when accessing post.blog).

What do you think should the future behavior of the GAE back-end:

a) Storing db.Keys should be the only option (note that all existing projects would need to dump/load data);
b) Storing db.Keys should be possible and default (existing projects would need to add an option to their settings);
c) Storing db.Keys should be possible, but the current storage should be the default;
d) Storing db.Keys should not be available.

Looking forward to some opinions / expectations on this matter.