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

many-array, flushCanonical bug when saving newly created elements #4149

Closed
olivierchatry opened this issue Feb 10, 2016 · 0 comments
Closed

Comments

@olivierchatry
Copy link

So here is my problem :

  • I have a project that can contains subProject
  • I'm using firebase
  • I create a new subProject, then save it, then save the project, so that all data and relations are saved.
  • Id I do the opposite ( save project, then save subProject ), then the sub-project new sub project get added twice, until I reload

Looking at the code of many-array, I can see why it is doing that :

    flushCanonical: function flushCanonical() {
      //TODO make this smarter, currently its plenty stupid
      var toSet = this.canonicalState.filter(function (internalModel) {
        return !internalModel.isDeleted();
      });

      //a hack for not removing new records
      //TODO remove once we have proper diffing
      var newRecords = this.currentState.filter(function (internalModel) {
        return internalModel.isNew();
      });
      toSet = toSet.concat(newRecords);
      var oldLength = this.length;
      this.arrayContentWillChange(0, this.length, toSet.length);
      this.set('length', toSet.length);
      this.currentState = toSet;
      this.arrayContentDidChange(0, oldLength, this.length);
      //TODO Figure out to notify only on additions and maybe only if unloaded
      this.relationship.notifyHasManyChanged();
      this.record.updateRecordArrays();
    },

The problems occurs with

      var newRecords = this.currentState.filter(function (internalModel) {
        return internalModel.isNew();
      });

The record is already in the relation, and get added again because it was not saved. Canonical state is fine, but the currentState is not.

I think I can try to fix that, if it is OK ?

olivierchatry pushed a commit to olivierchatry/data that referenced this issue Feb 11, 2016
olivierchatry pushed a commit to olivierchatry/data that referenced this issue Feb 12, 2016
@bmac bmac closed this as completed in d9c62c4 Feb 26, 2016
bmac pushed a commit to bmac/data that referenced this issue Mar 18, 2016
bmac pushed a commit that referenced this issue Mar 18, 2016
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

1 participant