Serialization 余烬:必须包含一个';id';在传递给';推动';

Serialization 余烬:必须包含一个';id';在传递给';推动';,serialization,ember.js,ember-data,Serialization,Ember.js,Ember Data,当前遇到以下错误:您必须在传递给“推送”的对象中包含失败快照列表的“id”。这是一个我继承了中期开发的代码库,我对Ember还相当陌生 据我所知,当后端没有用ID响应时,就会发生这种情况。服务器负载如下所示(返回带有嵌入式failedShotlist记录的警报对象): 由于后端不响应ID attr,因此需要使用序列化程序的“primaryKey”属性转换主键: 序列化程序/alert.js export default ApplicationSerializer.extend(EmbeddedR

当前遇到以下错误:
您必须在传递给“推送”的对象中包含失败快照列表的“id”
。这是一个我继承了中期开发的代码库,我对Ember还相当陌生

据我所知,当后端没有用ID响应时,就会发生这种情况。服务器负载如下所示(返回带有嵌入式failedShotlist记录的警报对象):

由于后端不响应ID attr,因此需要使用序列化程序的“primaryKey”属性转换主键:

序列化程序/alert.js

export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
  primaryKey: 'alertIdentifier',

  attrs: {
    'invite': { deserialize: 'records' },
    'failedShotlist': { deserialize: 'records' },
  },
});
export default ApplicationSerializer.extend({
  attrs: {
    'shotlistId': { key: 'shotlistIdentifier' },
    'projectId': { key: 'projectIdentifier' },
  },
});
export default ApplicationSerializer.extend({
  primaryKey: 'shotlistIdentifier',

  attrs: {
    'shotlistId': { key: 'shotlistIdentifier' },
    'projectId': { key: 'projectIdentifier' },
  },
});
我找不到这方面的任何提及,但我假设嵌入式记录由它们自己的序列化程序进一步序列化。现时的修订如下:

序列化程序/failedShotlist.js

export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
  primaryKey: 'alertIdentifier',

  attrs: {
    'invite': { deserialize: 'records' },
    'failedShotlist': { deserialize: 'records' },
  },
});
export default ApplicationSerializer.extend({
  attrs: {
    'shotlistId': { key: 'shotlistIdentifier' },
    'projectId': { key: 'projectIdentifier' },
  },
});
export default ApplicationSerializer.extend({
  primaryKey: 'shotlistIdentifier',

  attrs: {
    'shotlistId': { key: 'shotlistIdentifier' },
    'projectId': { key: 'projectIdentifier' },
  },
});
由于failedShotlist对象的ID也需要转换,因此我更新了它以包括primaryKey属性:

序列化程序/failedShotlist.js

export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
  primaryKey: 'alertIdentifier',

  attrs: {
    'invite': { deserialize: 'records' },
    'failedShotlist': { deserialize: 'records' },
  },
});
export default ApplicationSerializer.extend({
  attrs: {
    'shotlistId': { key: 'shotlistIdentifier' },
    'projectId': { key: 'projectIdentifier' },
  },
});
export default ApplicationSerializer.extend({
  primaryKey: 'shotlistIdentifier',

  attrs: {
    'shotlistId': { key: 'shotlistIdentifier' },
    'projectId': { key: 'projectIdentifier' },
  },
});

不幸的是,这导致了我最初遇到的相同错误。关于如何解决这个问题有什么想法吗?

我忽略了一点,适配器和序列化程序的源文件没有遵循代码库其余部分的命名约定

序列化程序被称为
failedShotlist.js
,与之相关的模型被称为
failedShotlist.js

将序列化程序文件重命名为
failed shotlist.js
允许我的现有代码工作:

export default ApplicationSerializer.extend({
  primaryKey: 'shotlistIdentifier'
}

您是否在应用程序序列化程序的或方法中放置了断点(假设您没有重写这些函数)并验证ID是否正确提取?@jelhan-adding
console.log(this.extractId(modelClass,resourceHash))normalize
方法中的code>为警报记录返回适当的ID,而为嵌入的失败快照列表记录返回null。所以我猜身份证提取不正确?如何解决此问题?ember cli始终使用kebab大小写作为文件名。我建议使用内置生成器(
ember help generate
)来避免此类问题。@jelhan-很高兴知道。这些文件是在我参与代码库之前创建的。