Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

How to get removed models for delete their from backend?

$
0
0

@kaermorchen wrote:

Hello.

I have model which has hasMany relationship - routePoints. In template I render objects from this relationship. And when I want to remove one point from routePoints I do it like this:

removeRoutePoint(routePoint) {
  this.get('model.routePoints').removeObject(routePoint);

  if (routePoint.get('isNew')) {
    routePoint.rollbackAttributes();
  } else {
    routePoint.deleteRecord();
  }
},

And then if user will save model I will delete removed points from backend:

// Inside save action
model.hasMany('points').hasManyRelationship.canonicalState.forEach(function(point) {
  if (point.isDeleted()) {
    point.save();
  }
});

model.save();

I'm not sure I'm doing it right. How can I get deleted model from store another way? Is there a more correct practice?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles