Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Embedded associations lost after commit #184

mkocher opened this Issue Apr 3, 2012 · 7 comments


None yet
5 participants

mkocher commented Apr 3, 2012

We're seeing an issue with associations where our embedded associated models are getting lost when we do a commit. Here's a test we wrote to demonstrate the problem:

test("committing the datastore should not lose embedded associations", function() {
  var Tag = DS.Model.extend({
      name: DS.attr('string')
    Person = DS.Model.extend({
      name: DS.attr('string'),
      tags: DS.hasMany(Tag, {key: 'tag_attributes', embedded: true})
    returnJson = {id: 1, name: "Tom Dale", tag_attributes: [{id: 5, name: "Doggy"}] },
    store = DS.Store.create({
      adapter: DS.Adapter.create({
        updateRecord: function(store, type, model) {
          store.didUpdateRecord(model, returnJson);

  store.load(Person, 1, { id: 1, name: "Tom Dale", tag_attributes: [{id: 5, name: 'a tag'}]});
  var personOne = store.find(Person, 1);

  equal(getPath(personOne, 'tags.length'), 1, "has the correct amount of tags before commit");
  equal(getPath(personOne, 'tags').objectAt(0), store.find(Tag, 5), "finds the associated tag before commit");

  personOne.set('name', 'foobar');

  equal(getPath(personOne, 'tags.length'), 1, "has the correct amount of tags after commit"); // FAILS
  equal(getPath(personOne, 'tags').objectAt(0), store.find(Tag, 5), "finds the previously associated tag after commit"); //FAILS

sandstrom commented Jun 11, 2012

I've got the same problem.

This is also an issue if the records are created from scratch, and adding the children using something like personOne.get("tags").addObject(Tag.createRecord({name: "Tage"})).

I have the same issue. Any workaround until it gets fixed?


sandstrom commented Jun 11, 2012

Our workaround is to reload the page after we've persisted or updated a model with associations. When the model is reloaded from scratch it works just fine.


wagenet commented Oct 18, 2012

At the moment, I'm pretty sure we don't explicitly support embedded associations anymore which renders this issue obsolete.

@wagenet wagenet closed this Oct 18, 2012


kurko commented Feb 10, 2013

Just leaving a comment here to express my frustration. After fulfilling relationships of a model and then committing it embedded, which works fine, setting the controller's content to App.Model.createRecord() to reset the controller and then committing again won't work embedded, or in other words, in the second time we commit, the embedded configuration is lost.

Solution right now is to either reload the page as @sandstrom said or not use embedded commits.


sandstrom commented Feb 10, 2013

@kurko At least our issue has been resolved and we use embedded relationships. Perhaps there is another nuance to your problem than the one outlined here? Also, try using the latest code from the two master branches and see if that helps. Otherwise, the irc channel and stackoverflow are great for solving problems like this.


kurko commented Feb 11, 2013

@sandstrom thanks for the response. I kept investigating and found that the issue is in the controller, which is not resetting the model properly, but making it look like it was the model the problem. I opened an issue about that.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment