Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading a record does not update canonical state of the record relationships #5610

Closed
Kilowhisky opened this issue Aug 29, 2018 · 1 comment

Comments

@Kilowhisky
Copy link

First of all here is the twiddle:

https://ember-twiddle.com/9d09b6673cb026a0303bab0d1bbc6f0a?openFiles=routes.index.js%2C

What is happening is that it appears that reloading a record with a hasMany association does not actually update the record's associations. Even forcing the hasMany using the hasMany('ref').push([]) does not force any associations to go away. The only way to make all the associations revert is to completely unload the records and reload them.

Given the following models:

// person.js
export default Model.extend({
  name: attr('string')
});
// contract.js
export default Model.extend({
  people: hasMany('person'),
  name: attr('string')
});

Only the last method of reloading actually works at reverting the hasMany('person') relationship:

reload(contract, people){
      contract.reload();
      people.update();
    },
    rollback(contract){
      contract.rollbackAttributes();
    },
    force(contract){
      contract.hasMany('people').push([]);
    },
    allTheThings(model){
      model.contract.unloadRecord();
      this.store.unloadAll('people');
      this.refresh(); // reload the route which loads the records again
    }

With models that are interconnected i essentially have to wipe all records in the store to effectively clear a canceled update of a record.

@runspired
Copy link
Contributor

when we receive new data for a relationship we do update the canonical state correctly, however, we don't blow away any local changes when the local change adds a new (unsaved) record. All other local changes will be blown away.

If you find you are retaining local changes that aren't new records, then please open a bug report! However if instead you find you are retaining local changes to records that are in a new state but which you thought you'd saved then likely the save action isn't being performed correctly. Typically this happens when sideposting relationships, and in this case using identifiers will fix this issue for you.

Closing as I don't think there's bug for us to fix here given the test coverage we have at this point, though maybe there was at the time this was opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants