Specifying pluralization of models

I’m converting a toy Rails app (Twitter clone) to use Ember and I’ve run across an interesting problem. My primary model is App.Status, but when it makes the ajax call to retrieve the statuses, it calls out to /statuss.

I didn’t find any official documentation on specifying pluralization of model names, but after some googling found that passing plurals: { model: 'models' } to DS.Store.extend() allows it. However, I didn’t find that this was the case. I’m not sure if this is a bug because I don’t know of the canonical way to do this. I’d be happy to send a PR to update docs if there’s a canonical way of doing this — and to update the code if this is indeed a bug.

My store.js:

Thing.Store = DS.Store.extend({
  revision: 12,
  adapter: DS.RESTAdapter.create({
    plurals: {
      status: 'statuses'
    }
  })
});

Console output because forum noobs can’t post screenshots:

> store = Ember.get(DS, 'defaultStore')
  Class { … }
> store.adapter.plurals
  Object {status: "statuses"}
> store.adapter.pluralize('status')
  "statuss"

Reproducing the problem: http://jsbin.com/itopaw/3/edit

Doesn’t the plurals object need to be inside of the configurations object?

In serializer.js…

  // define a plurals hash in your subclass to define
  // special-case pluralization
  pluralize: function(name) {
    var plurals = this.configurations.get('plurals');
    return (plurals && plurals[name]) || name + "s";
  },

Something like this? http://jsbin.com/itopaw/6/edit

It extends DS.RESTAdapter and my App.Store uses that instead of using DS.RESTAdapter directly. This works, but I thought there was supposed to be a way to tell Ember what the plurals were rather than tell it how to find them.

Check out http://emberjs.com/guides/models/the-rest-adapter/

DS.RESTAdapter.configure("plurals", {
  person: "people"
});

Huh, it’s right there, “pluralization customization”. It’s even in bold caps. I was looking for it in the store docs, since I figured it’d be a higher-level concern than being specific to the adapter — for serializing into JSON, for example. Thank you for pointing it out. :slight_smile:

Glad to help out a fellow ember-data brother :slight_smile:

It should be:

App.restSerializer.configure("plurals", {
  address: "addresses"
});

We are working on improving the docs for Ember Data so this shouldn’t be so confusing in the future.

I am still in the ‘lets get an inflector’ camp. This basically costs us 1kb gzip’d to get a rails compatible inflector. Maybe this is just optional for those who use ember-data with a rails/ams backend. But it does help satisfy the “it-just-works” case.

Old implementation, but we can use it to start a discussion: