Created
August 11, 2013 04:21
-
-
Save gbabiars/6203371 to your computer and use it in GitHub Desktop.
An example of the overrides needed to use camel case routes and json.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Serializer = DS.RESTSerializer.extend({ | |
keyForAttributeName: function(type, name) { | |
return name; | |
}, | |
keyForBelongsTo: function(type, name) { | |
var key = this.keyForAttributeName(type, name); | |
if (this.embeddedType(type, name)) { | |
return key; | |
} | |
return key + "Id"; | |
}, | |
keyForHasMany: function(type, name) { | |
var key = this.keyForAttributeName(type, name); | |
if (this.embeddedType(type, name)) { | |
return key; | |
} | |
return this.singularize(key) + "Ids"; | |
}, | |
keyForPolymorphicType: function(key) { | |
return key.replace(/Id$/, 'Type'); | |
}, | |
rootForType: function(type) { | |
var typeString = type.toString(); | |
Ember.assert("Your model must not be anonymous. It was " + type, typeString.charAt(0) !== '('); | |
// use the last part of the name as the URL | |
var parts = typeString.split("."); | |
var name = parts[parts.length - 1]; | |
return name.charAt(0).toLowerCase() + name.slice(1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment