emberjs/data — pull request #2078 by f3ndot (2014-07-10 18:24:35+00:00)
Title: [BUGFIX] Use declared mapping during serialization, even if keyForAttribute or keyForRelationship is defined

As you know, we're able to "map" an Ember Data attribute key to a completely different one that a backend expects by doing the following:

```js
var PostSerializer = DS.RESTSerializer.extend({
attrs: {
name: 'title'
}
});
```

The method responsible for this mapping during normalization is `JSONSerializer#normalizeUsingDeclaredMapping()`, which performs this mapping on both regular attributes & related attributes (`belongsTo`, `hasMany`).

#### There are a few problems on the serializing side: ####

1. If `keyForAttribute` is defined, it will clobber the mapping during serialization for regular attributes.
2. There is no mapping for `belongsTo` or `hasMany` attributes.

This Pull Request fixes those two issues, allowing for true bi-directional mapping (serialization and deserialization/normalization) as one would assume. If `keyForAttribute` or `keyForRelationship` is defined, they're ignored for the explicitly mapped attribute. Consider this example:

```js
var ApplicationSerializer = DS.RESTSerializer.extend({
// backend needs all keys to be snake_case
keyForAttribute: function(attr) {
return Ember.String.decamelize(attr);
},
keyForRelationship: function(attr, kind) {
return Ember.String.decamelize(attr);
},
});

var PostSerializer = ApplicationSerializer.extend({
attrs: {
// the backend requires the Post.name attribute to have a special serialized key, different
// from the backend's own convention of snake_casing serialized keys.
name: 'posttitle'
}
});
```