Ember.js data associations not saving

Viewed 1018

Let's say I have 2 models:

App.Address = DS.Model.extend({
   street: DS.attr('string'),
   person: DS.belongsTo('App.Person')
})

App.Person = DS.Model.extend({
  name: DS.attr('string'),
  addresses: DS.hasMany('App.Address')
})

Now I create a person

App.person = App.Person.createRecord({name: 'Bill'});
App.store.commit();

If I try to add an address to the person like this

address = App.Address.createRecord({street: '123 Fake Street'});
App.person.get('addresses').pushObject(address);

and commit the transaction

App.store.commit();

The new address will be saved however the person object will not be recognized as changed; even though the list of ids has gone from

{
  ...
  "addresses": []
}

to

{
  ...
  "addresses": [3]
}

Is there a way to let ember-data know that my person object has been changed and it needs to be saved?

Edit: Here is a jsfiddle illustrating the problem.

3 Answers
Related