outside2344
outside2344

Reputation: 2115

Where do I specify the pluralization of a model in Ember Data?

I have a model type that ends in -y: Security

How do I tell Ember Data to use /securities instead of /securitys to find resources for this?

Upvotes: 17

Views: 7283

Answers (3)

Willem de Wit
Willem de Wit

Reputation: 8742

This is the most relevant for pluralization as of ED 1.0.0-beta

With ember-data beta and up you can define irregular and uncountable pluralizations like this:

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

Example:

import DS from 'ember-data';
import Ember from 'ember';

var ApplicationAdapter = DS.RESTAdapter.extend({
  namespace: 'api'
});

var inflector = Ember.Inflector.inflector;
inflector.uncountable('advice'); //only makes call to /advice

export default ApplicationAdapter;

Upvotes: 13

willimus
willimus

Reputation: 241

Adding a hash to the create method doesn't seem to work with the latest version of Ember Data. I got the RESTAdapter.configure method to work as expected using the suggestion in this ticket: https://github.com/emberjs/website/pull/218 .

DS.RESTAdapter.configure("plurals", { person: "people" });
App.Store = DS.Store.extend({
  revision: 11,
  adapter: DS.RESTAdapter.create({
    namespace: 'api'
  })
});

Upvotes: 18

outside2344
outside2344

Reputation: 2115

After digging around in the Ember Data sources, what you need to do is add a hash to your create of DS.RESTAdapter, ala:

App.store = DS.Store.create({
  adapter: DS.RESTAdapter.create({ bulkCommit: false,
                                   plurals: {"security": "securities"} }),
  revision: 4
});

Upvotes: 17

Related Questions