Append an _id or _ids suffix to associations' keys. Embed objects in root according to their serializers' names.

An `_id` suffix will be appended to the name of HasOne associations, while `_ids` will be appended to the singularized name of HasMany associations. Association keys can still be overridden with the `key` option.

Furthermore, objects embedded in the root are now by default named according to their serializer, instead of the key used for their associations.
This commit is contained in:
Dan Gebhardt
2012-12-09 13:36:02 -05:00
parent a74fc6c8db
commit 3b1d2faf51
4 changed files with 61 additions and 41 deletions

View File

@@ -386,7 +386,7 @@ Now, any associations will be supplied as an Array of IDs:
"id": 1,
"title": "New post",
"body": "A body!",
"comments": [ 1, 2, 3 ]
"comment_ids": [ 1, 2, 3 ]
}
}
```
@@ -413,7 +413,7 @@ The JSON will look like this:
"comments": [
{ "id": 1, "body": "what a dumb post" }
],
"tags": [ 1, 2, 3 ]
"tag_ids": [ 1, 2, 3 ]
}
}
```
@@ -444,11 +444,11 @@ this:
"id": 1,
"title": "New post",
"body": "A body!",
"comments": [ 1, 2 ]
"comment_ids": [ 1, 2 ]
},
"comments": [
{ "id": 1, "body": "what a dumb post", "tags": [ 1, 2 ] },
{ "id": 2, "body": "i liked it", "tags": [ 1, 3 ] },
{ "id": 1, "body": "what a dumb post", "tag_ids": [ 1, 2 ] },
{ "id": 2, "body": "i liked it", "tag_ids": [ 1, 3 ] },
],
"tags": [
{ "id": 1, "name": "short" },