Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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 余烬之火中的多对多关系_Ember.js_Emberfire - Fatal编程技术网

Ember.js 余烬之火中的多对多关系

Ember.js 余烬之火中的多对多关系,ember.js,emberfire,Ember.js,Emberfire,我想知道是否有可能在灰烬之火中建立一种多对多的关系。 我有以下型号: //Employee name: DS.attr('string'), position: DS.attr('string'), accessoryPosition: DS.attr('string'), education: DS.attr('string'), experience: DS.attr('string'), imgUrl: DS.attr('string'), teachingIn: DS.attr('str

我想知道是否有可能在灰烬之火中建立一种多对多的关系。 我有以下型号:

//Employee
name: DS.attr('string'),
position: DS.attr('string'),
accessoryPosition: DS.attr('string'),
education: DS.attr('string'),
experience: DS.attr('string'),
imgUrl: DS.attr('string'),
teachingIn: DS.attr('string'),
subjects: DS.hasMany('subject', {async: true})

//Subject
name: DS.attr('string'),
courseDescriptionUrl: DS.attr('string'),
description: DS.attr('string'),
examDescriptionUrl: DS.attr('string'),
imgUrl: DS.attr('string'),
sportsSubject: DS.attr('boolean'),
outdoorSubject: DS.attr('boolean'),
commonSubject: DS.attr('boolean'),
teachers: DS.hasMany('employee', {async : true})
然后在我的员工控制器中:

update(subjects) {
      this.get('model.employee').set('subjects',subjects);
      this.get('model.employee').save();

    }

但他的只是将其添加到我/员工的端点。可以说,是否存在使关系相互关联的方法?

您必须手动将雇佣添加到主题中。实现这一点的方法如下:

update(subjects) {
   this.get('model.employee').set('subjects', subjects);
   this.get('model.employee').save();

   subjects.forEach(subject => {
     subject.get('teachers').addObject(subject);
   });
   subjects.invoke('save');
}
Array#pushObject
添加
subject
如果它不在数组中,并且
Array#invoke
对数组的每个元素调用
save
方法


希望这有帮助。

谢谢,有机会我会试试的!