wiri
wiri

Reputation: 91

Ember data pluralisation strange behavior

I have an ember application with a model named "media". "media" is a singular word. "medias" is the plural one. I define my model like this :

App.Media = DS.Model.extend({
    name: DS.attr('string')
});

Normally, "media" is the singular name of my model. So my api return this payload executing this.store.find('media', 1):

{
    "media": {
        "id" : 1,
        "name" : "media name"
    }
}

This give me an error: No model was found for 'medium'. Ember-data want me to return a payload like this: { "medium": {...}}. Why does enber-data singularize "media" ? It's already a singular word.

Moreover, adding irregular rule to the inflector don't affect the adapter at all.

Ember.Inflector.inflector.irregular('media', 'medias');

A complete example can be found here : http://emberjs.jsbin.com/bobaj/5/edit?js,output

Upvotes: 0

Views: 272

Answers (2)

wiri
wiri

Reputation: 91

This solves my problem:

Ember.Inflector.inflector.singular(/([ti])a$/i, '$1a');
Ember.Inflector.inflector.plural(/([ti])a$/i, '$1as');

Upvotes: 0

GJK
GJK

Reputation: 37369

Instead of using irregular, use singular. That is, this works:

Ember.Inflector.inflector.singular(/media/i, 'media');

And here's a JSBin showing that behavior.

Upvotes: 1

Related Questions