Skip to content

Commit

Permalink
CURRENT_API_REVISION: 12
Browse files Browse the repository at this point in the history
  • Loading branch information
dgeb committed Mar 4, 2013
1 parent 68f0080 commit 2aecaf9
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 3 deletions.
111 changes: 110 additions & 1 deletion BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,115 @@ App.Store = DS.Store.create({
This will remove the exception about changes before revision 2. You will
receive another warning if there is another change.

## Revision 12

Several changes have been made to serialization conventions for the
JSON and REST adapters.

### Foreign Key IDs for Arrays

In order to be consistent with singular foreign keys, the REST serializer
now serializes arrays of foreign keys with the singular form of the key name
suffixed with `_ids`. Therefore, just as `author_id` represents a single
author, `author_ids` (and not `authors`) now represents an array of authors
associated with a parent record.

Custom `key` mappings can be configured to override these defaults as needed.

### Sideload by Type

When loading data, the previous convention was to expect sideloaded data
to be included alongside a parent record based on the name of its relationship.

For instance, given the following model:

```js
App.Contact = DS.Model.extend({
name: DS.attr('string'),
phoneNumbers: DS.hasMany('App.PhoneNumber'),
homeAddress: DS.belongsTo('App.Address')
workAddress: DS.belongsTo('App.Address')
});
```

... the following payload would be deserialized properly:

```js
{
"contact": {
"id": 1,
"name": "Dan",
"phone_numbers": [1, 2],
"home_address_id": 3
"work_address_id": 4
},
"phoneNumbers": [
{
"id": 1,
"number": "555-1212"
},
{
"id": 2,
"number": "555-2222"
}
],
"homeAddress": [
{
"id": 3,
"zip_code": "03086"
}
],
"workAddress": [
{
"id": 4,
"zip_code": "94107"
}
]
}
```

Now, `homeAddress` and `workAddress` will be expected to be sideloaded
together as `addresses` because they are the same type. Furthermore, the
default root naming conventions (underscore and lowercase) will now also
be applied to sideloaded root names.

The new, more consistent and concise conventions for sideloading are:

```js
{
"contact": {
"id": 1,
"name": "Dan",
"phone_number_ids": [1, 2],
"home_address_id": 3
"work_address_id": 4
},
"phone_numbers": [
{
"id": 1,
"number": "555-1212"
},
{
"id": 2,
"number": "555-2222"
}
],
"addresses": [
{
"id": 3,
"zip_code": "03086"
},
{
"id": 4,
"zip_code": "94107"
}
]
}
```

Custom `sideloadAs` and `key` mappings can still be configured to override
these defaults as required.

## Revision 11

### Payload Extraction
Expand All @@ -52,7 +161,7 @@ payload for a blog post and its comments may look like this:
"post": {
"id": 1,
"title": "Rails is omakase",
"comment_ids": [1, 2, 3]
"comments": [1, 2, 3]
},

"comments": [{
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-data/lib/core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window.DS = Ember.Namespace.create({
// this one goes to 11
CURRENT_API_REVISION: 11
// this one goes past 11
CURRENT_API_REVISION: 12
});

2 comments on commit 2aecaf9

@sly7-7
Copy link
Contributor

@sly7-7 sly7-7 commented on 2aecaf9 Mar 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated my project against this, it did'nt work at the first time because the default gem 'active_model_serializer' does not serialize the expected json. I had to refer to the current rails-api/active_model_serializer master. Perhaps I will not be the only getting in trouble with this.

@workmanw
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is great for us, previously we had to loop through our payload and load each type separately. Thanks!

Please sign in to comment.