5
votes

In Ember data 0.13, pluralization was defined as follows:

DS.RESTAdapter.configure("plurals", {
 category: "categories"
});

Configure no longer exists and thus there needs to be another way to define plurals.

By magic, it seems that if I do a find via "return this.store.find('category');", the JSON call includes /categories and not /categorys, although I have not at all specified that the plural of category is categories ...

How can Ember data determine this ? Is there a way to override ?

Thx

5
I have no in-depth knowledge, but I believe the functionality is contained in the ember-inflector module (which I'm told can be replaced). See this commit : github.com/emberjs/data/commit/…David McMullin
Thx. There is indeed a rule that converts "y" to "ies"; thus category becomes categories in findAll. Do not see how to override, but have no immediate need since Ember data automatically pluralizes.cyclomarc

5 Answers

6
votes

I'm using the following in app.js:

var inflector = Ember.Inflector.inflector;
inflector.irregular("patient", "patients");
5
votes

I am not sure how to actually navigate to the REST adapter documentation anymore, but I recently updated the Pluralization Customization section with these examples:

Ember.Inflector.inflector.irregular('formula', 'formulae');
Ember.Inflector.inflector.uncountable('advice');
3
votes

If the concern is to avoid the pluralization of the model name in the url only, you can override the pathForType function which is responsible of the transformation. It doesn't affect the pluralize function and finally it is a way of configuring the buildUrl process.

            App.ApplicationAdapter = DS.RESTAdapter.extend({
            namespace: 'rest/api',

            pathForType: function(type) {
                return (type);
            }
        });
2
votes

It seems there is now a default pluralization for specific words such as category, tomato, etc.

See: https://github.com/emberjs/data/commit/9325a1dea594b8ff752886eb7a9d752785282e07

Thx to David McMullin !

2
votes

I was able to override automatic pluralization of one of my model names by doing this using Ember Data v1.0.0-beta.2

Ember.Inflector.inflector.rules.uncountable['dontpluralizemebro'] = true;

Just replace dontpluralizemebro with the word you don't want pluralized. I put this at the top of my app.js file. Obviously this is undocumented and may change at any time in a future release.

I can understand how the auto pluralization can be a nicety but IMHO I think it wastes valuable KB's especially on mobile for something that isn't wholly necessary.