lundi 30 janvier 2017

Pushing new object to store causes bug in has many relationship - Ember

So what's going on: I have a feed object that hasMany feed tracks. The template loops through those feed tracks and displays their associated track.


  


When a user decides to like a track, that feed track is removed from the array and another is added from the server response:

shareFeedTrack(feedTrack) {
  this.modelFor('master.feed').get('feedTracks').removeObject(feedTrack);
  feedTrack.share().then((response) => {
    if (response != null) {
      var normalizedResponse = this.store.normalize('feed-track', response);
      this.store.push(normalizedResponse);
    }
  }.bind(this));
}

But when the push occurs, the template displays the previously removed track at the top again, as if the model reloaded and didn't register that the top item had been removed.

I've tried to delete the record and save, but again, after pushing the new object, the feed still shows an empty template for the record that had been removed, as if the object still existed in the relations array.

Nothing is coming from the server that could cause this, so it must be a caching issue. It's driving me crazy. Ember data is great but it seems to make things that should be simple (removing an object and adding another) a stressful endeavor.




Aucun commentaire:

Enregistrer un commentaire