samedi 10 janvier 2015

How to delete all records in a model's hasMany association in Ember.js

I have a tournament model with a collection of matches associated to it. Suppose I want to destroy all of the matches in the collection at once, how should that be done? Here is what I've tried:



var matches = tournament.get('matches').toArray();
for (var i = 0; i < matches.length; i++) {
matches[i].destroyRecord();
}
tournament.save().then(function(tournament) {
that.transitionTo('tournaments.setup', tournament);
});


This toArray bit doesn't seem right, but it prevents modifying an iterable as I iterate through it. It seems that there should be a way to just destroy all of these matches at once, then save the tournament.


Aucun commentaire:

Enregistrer un commentaire