nicolaiarocci/eve — pull request #88 by bcattle (2013-09-02 21:25:43+00:00)
Title: Embedded resource serialization: one-to-one

This addresses #68. I implemented @nicolaiarocci's idea described in [this comment](https://github.com/nicolaiarocci/eve/issues/68#issuecomment-21536899).

To use, you define a resource with a field of `'type': 'objectid'` with a `data_relation` pointing to the PK of another collection. Inside the `data_relation` set `'embeddable': True`.

Then, a GET request to a URL like `/invoices/?embedded={"user":1}` will return a serialized representation of the `user` document referenced within the containing document. The embedded representation will obey all `projection`, etc. conditions specified in the `DOMAIN` config.

For now, this only supports one level of embedding, and only supports one-to-one relationships. It would be easy to extend to recursive embedding (allowing something like `/invoices/?embedded={"user":1, "user.address":1}`. It would also be easy to extend to one-to-many relationships, i.e.

``` python
DOMAIN = {
'letter': {
'schema': {
'authors': {
'type': 'list',
'schema': {
'type': 'objectid',
'data_relation': {
'collection': 'user',
'field': '_id',
'embeddable': True
},
},
# ...
```

If somebody wants these features I can add them.