hasMany 关系之一不是 POST 回服务器。你应该如何建模双向关系?
以下是相关对象:
Encompass.Selection = DS.Model.extend({
  text: DS.attr('string'),
  submission: DS.belongsTo('submission', {inverse: 'selections'}),
});
Encompass.Submission = DS.Model.extend({
  shortAnswer: DS.attr('string'),
  selections: DS.hasMany('selection'),
  testing: DS.hasMany('folder'),
  workspaces: DS.hasMany('workspace'),
});
和一个控制器动作:
testing2: function() {
  var submission = this.get('model');
  console.log(submission.get('selections.length'));
  var newSelection = this.get('store').createRecord('selection', {
    text: 'testing2 selection' + new Date().getMilliseconds(),
    submission: submission,
    coordinates: 'bogus coords',
    workspace: this.get('currentWorkspace')
  });
  //newSelection.save();
  console.log(submission.get('selections.length'));
  submission.save();
},
当我点击 testing2 操作时,控制台显示提交首先有 1 个选择,然后是第二个。该save()方法触发了一个帖子,但它缺少 selections 对象:
  {
    submission: {
      shortAnswer: "short", 
      testing:     [],
      workspaces:  ["5271d0147205f15e31000001"]
    }
  }
我试过删除和添加逆映射。奇怪的部分是其他有很多关系工作。
我发现唯一有效的方法是submission从Selection.