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.
// 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";
},
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.
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.
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: