Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Data 1.0.0: How does pluralization works?

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

like image 204
cyclomarc Avatar asked Sep 01 '13 17:09

cyclomarc


3 Answers

I'm using the following in app.js:

var inflector = Ember.Inflector.inflector;
inflector.irregular("patient", "patients");
like image 188
Riccardo Bartoli Avatar answered Oct 16 '22 09:10

Riccardo Bartoli


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');
like image 5
gerry3 Avatar answered Oct 16 '22 10:10

gerry3


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);
            }
        });
like image 3
Christophe Lambert Avatar answered Oct 16 '22 10:10

Christophe Lambert