Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 有许多关系序列化:';ids';使用EmbeddedRecordsMixin,如何;侧推“;?_Ember.js_Ember Data_Rails Activerecord - Fatal编程技术网

Ember.js 有许多关系序列化:';ids';使用EmbeddedRecordsMixin,如何;侧推“;?

Ember.js 有许多关系序列化:';ids';使用EmbeddedRecordsMixin,如何;侧推“;?,ember.js,ember-data,rails-activerecord,Ember.js,Ember Data,Rails Activerecord,我正在使用DS.ActiveModelAdapter 将新的余烬数据记录保存到我的后端,我想发送: { author: { name: 'Mike', book_ids: [null, null] }, books: [ { name: 'book1' }, { name: 'book2' } ] } 我原以为这就是se

我正在使用DS.ActiveModelAdapter

将新的余烬数据记录保存到我的后端,我想发送:

{
    author: {
        name: 'Mike',
        book_ids: [null, null]
    },
    books: [
        {
            name: 'book1'
        },
        {
            name: 'book2'
        }
    ]
}
我原以为这就是serialize:“ids”的用途,但当我使用此配置时:

App.AuthorSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
   attrs: {
      books: {serialize: 'ids'}
   }
});
我刚刚得到:

{
    author: {
        name: 'Mike',
        book_ids: [null, null]
    }
}
更新:

声明说:“有一个选项可以通过使用serialize:'ids'不在序列化负载中嵌入JSON。如果您根本不想发送关系,可以使用serialize:'no'。”


因此,不清楚是添加了ID还是将ID和记录放在一边。我想在这里确认一下,这些记录不是通过使用serialize:'ids'添加到一边的,在这种情况下,我可以做些什么来“侧推”嵌套记录。

似乎EmbeddedRecordsMixin不是解决方法

余烬数据模型片段对我来说是完美的解决方案。

按照我在问题中给出的示例,使用后者,相应的模型将是:

App.Author = DS.Model.extend({
  name: DS.attr('string'),
  books: DS.hasManyFragments('book')
});

App.Book = DS.ModelFragment.extend({
  name: DS.attr('string')
});