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

后端 未结 3 941
故里飘歌
故里飘歌 2020-12-29 07:29

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?

相关标签:
3条回答
  • 2020-12-29 07:49

    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
    });
    
    0 讨论(0)
  • 2020-12-29 07:58

    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'
      })
    });
    
    0 讨论(0)
  • 2020-12-29 08:10

    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;
    
    0 讨论(0)
提交回复
热议问题