2016-07-11 9 views
0

Ich habe eine product Modell, und eine /products/ Route - jedoch ember Daten sendet eine Anfrage an host/api/v1/product statt host/api/v1/products - warum ist das?Ember Data Plural Serializer

Auch, wie kann ich den Plural Endpunkt für einzelne Produkt holen? dh: host/api/v1/product/1

Antwort

1

prüfen buildURL Methode

By default, it pluralizes the type's name (for example, 'post' 
becomes 'posts' and 'person' becomes 'people'). To override the 
pluralization see [pathForType](#method_pathForType). 

und es gibt Liste der Unter Methoden (https://github.com/emberjs/data/blob/v2.6.1/addon/-private/adapters/build-url-mixin.js#L54)

switch (requestType) { 
    case 'findRecord': 
    return this.urlForFindRecord(id, modelName, snapshot); 
    case 'findAll': 
    return this.urlForFindAll(modelName, snapshot); 
    case 'query': 
    return this.urlForQuery(query, modelName); 
    case 'queryRecord': 
    return this.urlForQueryRecord(query, modelName); 
    case 'findMany': 
    return this.urlForFindMany(id, modelName, snapshot); 
    case 'findHasMany': 
    return this.urlForFindHasMany(id, modelName, snapshot); 
    case 'findBelongsTo': 
    return this.urlForFindBelongsTo(id, modelName, snapshot); 
    case 'createRecord': 
    return this.urlForCreateRecord(modelName, snapshot); 
    case 'updateRecord': 
    return this.urlForUpdateRecord(id, modelName, snapshot); 
    case 'deleteRecord': 
    return this.urlForDeleteRecord(id, modelName, snapshot); 
    default: 
    return this._buildURL(modelName, id); 
} 

so können Sie eine für Ihre Zwecke

0

-Update neu definieren Ihr Adapter wie unten:

import JSONAPIAdapter from 'ember-data/adapters/json-api'; 

export default JSONAPIAdapter.extend({ 
    pathForType: function(type) { 
     var camelized = Ember.String.camelize(type); 
     return Ember.String.singularize(camelized); 
    } 
}); 
Verwandte Themen