简体   繁体   中英

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

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.

This solves my problem:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM