Skip to content

Commit

Permalink
Merge pull request #3035 from Dremora/key_serializer_docs
Browse files Browse the repository at this point in the history
Add method argument to key serialization docs
  • Loading branch information
bmac committed May 1, 2015
2 parents 6d47319 + e23bcea commit 8c81d41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions packages/ember-data/lib/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export default Serializer.extend({
var payloadKey = this._getMappedKey(key);

if (payloadKey === key && this.keyForAttribute) {
payloadKey = this.keyForAttribute(key);
payloadKey = this.keyForAttribute(key, 'serialize');
}

json[payloadKey] = value;
Expand Down Expand Up @@ -671,7 +671,7 @@ export default Serializer.extend({
serializePolymorphicType: function(snapshot, json, relationship) {
var key = relationship.key,
belongsTo = snapshot.belongsTo(key);
key = this.keyForAttribute ? this.keyForAttribute(key) : key;
key = this.keyForAttribute ? this.keyForAttribute(key, "serialize") : key;
if (Ember.isNone(belongsTo)) {
json[key + "_type"] = null;
Expand Down Expand Up @@ -1032,42 +1032,44 @@ export default Serializer.extend({
```javascript
App.ApplicationSerializer = DS.RESTSerializer.extend({
keyForAttribute: function(attr) {
keyForAttribute: function(attr, method) {
return Ember.String.underscore(attr).toUpperCase();
}
});
```
@method keyForAttribute
@param {String} key
@param {String} method
@return {String} normalized key
*/
keyForAttribute: function(key) {
keyForAttribute: function(key, method) {
return key;
},

/**
`keyForRelationship` can be used to define a custom key when
serializing relationship properties. By default `JSONSerializer`
does not provide an implementation of this method.
serializing and deserializing relationship properties. By default
`JSONSerializer` does not provide an implementation of this method.
Example
```javascript
App.PostSerializer = DS.JSONSerializer.extend({
keyForRelationship: function(key, relationship) {
return 'rel_' + Ember.String.underscore(key);
keyForRelationship: function(key, relationship, method) {
return 'rel_' + Ember.String.underscore(key);
}
});
```
@method keyForRelationship
@param {String} key
@param {String} relationship typeClass
@param {String} method
@return {String} normalized key
*/

keyForRelationship: function(key, typeClass) {
keyForRelationship: function(key, typeClass, method) {
return key;
},

Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function coerceId(id) {
```js
App.ApplicationSerializer = DS.RESTSerializer.extend({
keyForAttribute: function(attr) {
keyForAttribute: function(attr, method) {
return Ember.String.underscore(attr).toUpperCase();
}
});
Expand Down

0 comments on commit 8c81d41

Please sign in to comment.