Removing only Relation in Ember-Data

Hi All-

I’d like to remove a relation in ember data. I have two models, wishlists and colleges.

App.Wishlist = DS.Model.extend({
  colleges: DS.hasMany('college'),
  grade: DS.attr('string')
});

And an action that should remove the college from the wishlist (but keep the college) and then reload the page.

removeCollegeFromWishlist: function(college){
      var wishlist = this.get('model').content[0];
      wishlist.get('colleges').removeObject(this.store.get('colleges',college.id));
      wishlist.save().then(function (){
        this.transitionToRoute('student.wishlist');
      });
    },

However, the PUT request generate by this still contains all of the ids that were in the original load, ie, it does not delete the relationship.

A few things without knowing your complete setup. first.

  • I guess: “removeCollegeFromWishlist” is a method in your controller? you shouldnt need to write .content[0]… And to remove an object you dont need to fetch the record. Just:

    removeCollegeFromWishlist: function(college){ var wishlist = this.get(‘model’); wishlist.get(‘colleges’).removeObject(college);

    wishlist.save().then(function (fetchedWishlist){ // fetchedWishlist shouldnt contain college anymore this.transitionToRoute(‘student.wishlist’); });