0

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

Rigel
  • 882
  • 1
  • 11
  • 32

1 Answers1

0

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.

ebryn
  • 4,407
  • 1
  • 23
  • 21
  • Hi ebryn thanks for the reply. Still facing issue I have updated question and found a similar query for ember-mode-firebase-adapter here http://stackoverflow.com/questions/18772269/creating-child-records-with-ember-model/18779456#18779456 – Rigel Sep 13 '13 at 06:19
  • Could you give more information? I can't find any documentation on this. – blaineh Dec 07 '13 at 06:28