Using the RESTAdapter without transactions - is this a terrible idea?

@nragaz That’s really helpful, thanks for sharing this (and your blog post)! I was pulling my hair with this issue:

but your solution provides a good alternative.

Just two things:

  • just in case someone else can’t make it work: I believe you need one of the latest ember-data builds (I was on an older one and several functions were missing)

  • there seems to be an issue when relationships are involved. If a newly created record is associated to the one you are trying to save, you will get this error:

    Attempted to handle event willCommit on App.User:ember415:null while in state rootState.loaded.created.inFlight.

In addition, inyour forEach loop, a record might be a relationship and I think they need to be treated in a specific way (they don’t have a “get” method).

So I ended up modifying it a bit. To be honest I am not totally sure about this code (cf the try/catch: I don’t know how to tell if a record is a relationship vs a model, and more generally I find the “state machine” thing difficult to grasp when relationships are involved) and not thoroughly tested, but it works here:

commit: function(store, commitDetails) {
    var bucket, records;

    for (bucket in commitDetails) {
      records = commitDetails[bucket];
      records.forEach(function(record) {
		try {
			if (!record.get('isSaving')){
	        	return record.send('willCommit');
			}
		}
		catch(err){}
      });
    }
    return this.save(store, commitDetails);
}