title: How to rollback relationship changes in EmberData
body: <p>I have two models with parent-child relationship: training and exercise:</p>
  
  <pre class="lang-js prettyprint-override"><code>App.Training = DS.Model.extend({
    exercises: DS.hasMany('App.Exercise')
  })
  
  App.Exercise = DS.Model.extend({
    training: DS.belongsTo('App.Training')
  })
  </code></pre>
  
  <p>I want to have a page where a training with all its related exercises is displayed. If the user presses the <code>Edit</code> button, the page becomes editable with the possibility of adding new exercises. I also want to have a <code>Cancel</code> button which discards all the changes made. </p>
  
  <p>Here is my controller:</p>
  
  <pre class="lang-js prettyprint-override"><code>App.TrainingsShowController = Em.ObjectController.extend({
    editing: false,
  
    edit: function() {
      this.set('editing', true);
      transaction = this.get('store').transaction();
      transaction.add(this.get('model'));
      this.get('model.exercises').forEach(function(x){
        transaction.add(x);
      });
    },
  
    cancel: function() {
      this.set('editing', false);
      this.get('model.transaction').rollback();
    },
  
    save: function() {
      this.set('editing', false);
      this.get('model.transaction').commit();
    },
  
    addExercise: function() {
      this.get('model.exercises').createRecord({});
    }
  })
  </code></pre>
  
  <p>There are four event handlers in the controller:</p>
  
  <ol>
  <li><code>edit</code>: The user pressed the <code>Edit</code> button: a transaction is created, the page is put into "Editing" mode.</li>
  <li><code>cancel</code>: The user pressed the <code>Cancel</code> button: transaction is rolled back and back to "Normal" mode.</li>
  <li><code>save</code>: The user pressed the <code>Save</code> button: transaction is commited and back to "Normal" mode.</li>
  <li><code>addExercise</code>: The user pressed the <code>Add exercise</code> button: a new exercise is created (in the same transaction) and added to the trainings.</li>
  </ol>
  
  <p>The rollback functionality works fine except for newly created records: if I push the <code>Edit</code> button, add a new exercise and push the <code>Cancel</code> button, the newly created exercise stays on the page.</p>
  
  <p>What is the best way to get rid of the discarded child record?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've created a jsFiddle to reproduce problem, but it worked. Unlike my application here I used <code>DS.FixtureAdapter</code>: <a href="http://jsfiddle.net/tothda/LaXLG/13/">http://jsfiddle.net/tothda/LaXLG/13/</a></p>
  
  <p>Then I've created an other one using <code>DS.RESTAdapter</code> and the problem showed up: <a href="http://jsfiddle.net/tothda/qwZc4/5/">http://jsfiddle.net/tothda/qwZc4/5/</a></p>
  
  <p>In the fiddle try: Edit, Add new and then Rollback.</p>
  
  <p>I figured it out, that in case of the RESTAdapter when I add a new child record to a <code>hasMany</code> relationship, the parent record won't become dirty. Which seems fine, but when I rollback the transaction, the newly created child record stays in the parent's <code>ManyArray</code>.</p>
  
  <p>I still don't know, what's the best way to handle the situation.</p>