Permalink
Browse files

Allow setting plurals via adapter config API

  • Loading branch information...
1 parent 82841c2 commit 7da1b290ae0ba29492b288b94749948f1c552d38 @tomdale tomdale committed Dec 30, 2012
@@ -68,8 +68,6 @@ DS.RESTAdapter = DS.Adapter.extend({
init: function() {
this._super.apply(this, arguments);
-
- get(this, 'serializer').plurals = this.plurals || {};
},
shouldSave: function(record) {
@@ -210,7 +210,8 @@ DS.JSONSerializer = DS.Serializer.extend({
// define a plurals hash in your subclass to define
// special-case pluralization
pluralize: function(name) {
- return this.plurals[name] || name + "s";
+ var plurals = this.configurations.get('plurals');
+ return (plurals && plurals[name]) || name + "s";
},
rootForType: function(type) {
@@ -706,7 +706,7 @@ DS.Adapter.reopenClass({
// If a mapping configuration is provided, peel it off and apply it
// using the DS.Adapter.map API.
- var mappings = newValue.mappings;
+ var mappings = newValue && newValue.mappings;
if (mappings) {
this.map(key, mappings);
delete newValue.mappings;
@@ -962,7 +962,7 @@ DS.Serializer = Ember.Object.extend({
reifiedConfigurations = Ember.Map.create();
configurations.forEach(function(key, mapping) {
- if (typeof key === 'string') {
+ if (typeof key === 'string' && key !== 'plurals') {
var type = Ember.get(Ember.lookup, key);
Ember.assert("Could not find model at path" + key, type);
@@ -11,7 +11,12 @@ module("the REST adapter", {
ajaxType = undefined;
ajaxHash = undefined;
- adapter = DS.RESTAdapter.create({
+ var Adapter = DS.RESTAdapter.extend();
+ Adapter.configure('plurals', {
+ person: 'people'
+ });
+
+ adapter = Adapter.create({
ajax: function(url, type, hash) {
var success = hash.success, self = this;
@@ -29,10 +34,6 @@ module("the REST adapter", {
serializer = get(adapter, 'serializer');
- serializer.plurals = {
- person: 'people'
- };
-
store = DS.Store.create({
adapter: adapter
});

0 comments on commit 7da1b29

Please sign in to comment.