ember-data-model-fragments icon indicating copy to clipboard operation
ember-data-model-fragments copied to clipboard

Deleting an unsaved fragment from store

Open dpigera opened this issue 6 years ago • 0 comments

Hello, I'm very sure I'm doing this incorrectly. I have a route for creating a model setup as shown:

export default Route.extend(AuthenticatedRouteMixin, {
  model() {
    return RSVP.hash({
      systemDatasource: this.store.createRecord('system-datasource', {
        name: null,
        basePath: null,
        datasourceType: null,
        s3: this.store.createFragment('system-datasource-s3', {
          'bucket': null,
          'basePath': null,
          'accessKey': null,
          'secretKey': null
        }),
        sftp: this.store.createFragment('system-datasource-sftp', {})
      }),
      datasourceList: ['s3','sftp']
    })
  },

  actions: {
    discard() {
      let systemDatasource = this.modelFor(this.routeName).systemDatasource;  
      systemDatasource.deleteRecord();
      this.transitionTo('settings.system-datasources');
    }
  }
});

When I call the discard() method (i.e. user decides to abort creating a new object), I notice the uncommitted system-datasource model is removed from the store correctly.

However, the system-datasource-s3 and system-datasource-sftp models are left behind:

screen shot 2018-06-03 at 9 39 29 am

Can you kindly advise on how I can go about removing those unsaved fragments from the store? Thank you so much!

dpigera avatar Jun 03 '18 14:06 dpigera