title: unloading the relationships in ember
body: <p>I am developing an app that deals with files.I have a model called file.It has comments model in a has many relationships.Lets say I have a folder F1.F1 contains 3 files and 1 Folder called (F2).F2 has 3 files.Supposing If am deleting F1.The deleteRecord is performed on F1.I can able to unload the model that are in direct relationship with F1.for this I am using cascade-delete mixin.How can I unload the relation ship model that has nested relation ship with F1 such as the files under F2.</p>
  
  <p>model/file.js</p>
  
  <pre><code> export default DS.Model.extend({
        name: DS.attr(),
        comments:('comment', { cascadeDelete: true }
      });
  </code></pre>
  
  <p>mixins/cascade-delete.js</p>
  
  <pre><code>import Ember from 'ember';
  
  export default Ember.Mixin.create({
    deleteRecord(store, type, snapshot) {
      let recordsToUnload = [];
  
      // collect all records to unload into recordsToUnload variable
      snapshot.record.eachRelationship((name, descriptor) =&gt; {
        let { options, kind } = descriptor;
        let relationshipName = descriptor.key;
  
        if (options.cascadeDelete &amp;&amp; kind === 'hasMany') {
          let hasManyRecords = snapshot.record.hasMany(relationshipName).value();
          if (hasManyRecords !== null) {
            hasManyRecordsArray = hasManyRecords.toArray();
          }
          recordsToUnload = recordsToUnload.concat(hasManyRecords);
        }
  
        if (options.cascadeDelete &amp;&amp; kind === 'belongsTo') {
          let belongsToRecords = snapshot.record.belongsTo(relationshipName).value();
          recordsToUnload = recordsToUnload.concat([ belongsToRecords ]);
        }
      });
  
      return this._super(...arguments).then((response) =&gt; {
        recordsToUnload.forEach((childRecord) =&gt; {
          store.unloadRecord(childRecord);
        });
  
        return response;
      });
    }
  });
  </code></pre>