SuperNinja
SuperNinja

Reputation: 1606

Emberjs: Ember Appkit - model pluralization

I am using ember appkit for a beginner ember project. I am working with an existing API and my model looks as such:

export default Ember.Route.extend({
model: function(){
    return this.store.find('prequalification');
}

});

When the API call happens, the URL is pluralized, prequalifications. I am trying to configure the RestAdapter but not sure where in the code flow this should happen.

Thanks for any help

Upvotes: 0

Views: 138

Answers (2)

sabithpocker
sabithpocker

Reputation: 15576

Irregular or uncountable pluralizations can be specified via Ember.Inflector.inflector:

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

This will tell the REST adapter that requests for App.Formula requests should go to /formulae/1 instead of /formulas/1.

REF : http://emberjs.com/guides/models/the-rest-adapter/#toc_pluralization-customization

Upvotes: 1

Lamdas Everywhere
Lamdas Everywhere

Reputation: 1686

It happens in the RestAdapter, you're correct...

check the pathForType attribute out out:

https://github.com/emberjs/data/blob/v1.0.0-beta.6/packages/ember-data/lib/adapters/rest_adapter.js#L476

Their example is:

DS.RESTAdapter.reopen({
  pathForType: function(type) {
    var decamelized = Ember.String.decamelize(type);
    return Ember.String.pluralize(decamelized);
  };
});

Upvotes: 0

Related Questions