我有一些名字相似的模型:
问题-statuse.js 问题-type.js
问题类型工作正常,但问题状态导致问题:
WARNING: Encountered "issue_statuses" in payload, but no model was found for model name "issue-status" (resolved model name using soporte@serializer:issue-statuse:.modelNameFromPayloadKey("issue_statuses"))
//<!--app/adapters/application.js-->
import Ember from 'ember';
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
namespace: 'api/v1',
host: 'http://127.0.0.1:3000',
coalesceFindRequests: true,
headers: {
withCredentials: true,
Authorization: 'Basic eG9qbzpzZWNyZXQ=',
crossDomain: true
},
pathForType: function(type) {
return Ember.String.underscore(type)+'s';
}
});
// added a 's' for pluralize names, as when we need in underscore are in singular once again ...
//<!--app/models/issue-statuse.js-->
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
short: DS.attr('string'),
plural: DS.attr('string'),
created_at: DS.attr('date'),
active: DS.attr('boolean')
});
我在Serializer中有一个解决方法,我不喜欢它,但有了它它可以正常工作:
//<<!--app/serializers/issue-statuse.js
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
modelNameFromPayloadKey: function(payloadKey) {
if (payloadKey === 'issue_statuses') {
return this._super("issue-statuse"); //this._super(payloadKey.replace('blog/', ''));
} else {
return this._super('issue-statuse'); //this._super(payloadKey);
}
}
});
但如果我使用此序列化程序,我就会收到弃用警告:
Your custom serializer uses the old version of the Serializer API, with `extract` hooks. Please upgrade your serializers to the new Serializer API using `normalizeResponse` hooks instead.
所以,我有两个选择,第一个是尝试解决为什么Ember找不到我的模型,第二个是使用序列化器并尝试理解弃用以及如何消除它。
我更喜欢选项一: - )
谢谢,
这是模型文件名称中的拼写错误,它是单数:
//<!--app/models/issue-statuse.js-->
我已完全删除app / serializers / issue-statuse.js并使用变形器创建了初始化程序:
//<!--/app/initializers/inflector.js-->
import Ember from 'ember';
export function initialize(/* container, application */) {
var inflector = Ember.Inflector.inflector;
inflector.uncountable('aamc-pcrs');
inflector.irregular('issue-statuse', 'issue-statuses');
}
export default {
name: 'inflector',
initialize: initialize
};
我正在使用
pathForType: function(type) {
return Ember.String.underscore(type)+'s';
},
适配器中的用于更改 - 用于_ 例如,我的后端API需要issue_statuses而不是issue-status。也许我可以重命名变形器中的表并删除这一行......