Ember-Model hasMany does not save model emberjs

走远了吗. 提交于 2019-12-11 23:09:45

问题


I am trying to achieve this Department -HasMany->Contacts.

Have no clue Department gets saved but Contacts doesnt get Saved

you can refer this section in jsbin

App.NewcontactController = Ember.ObjectController.extend({
 needs: ['department'],
 save: function () {
     var department = this.get('controllers.department').get('model');
      var newContact = App.Contact.create({
         name: this.get('name'),
         department: department
     });
     department.get('contacts').addObject(newContact);
     console.log(department);
     console.log(newContact);
     department.get('contacts').save();

     department.save();
     console.log('---saved contact---');
     this.transitionTo('contact',newContact);
 }

});

Firebug LocalStorage

Contact-1        "{"id":"1","department_id":"1"}" 
Department-1     "{"id":"1","name":"A","contact_ids":[]}" //NO ids :(

*My Jsbin **

UPDATED Ember-Model with Ember-Model-LocalStorage


回答1:


Saving a parent doesn't save children. You are responsible for saving the children yourself. There is a save method on the hasMany relationship to make this a little easier.



来源:https://stackoverflow.com/questions/18686562/ember-model-hasmany-does-not-save-model-emberjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!