Relationship Fragility
zamoore opened this issue · 0 comments
zamoore commented
Hey all, I've been scratching my head about this for some time now.
I have the following action.
saveCampaign(campaign) {
RSVP.all(get(campaign, 'players').map((player) => player.save()))
.then(() => campaign.save().then(() => {
this.notifications.success('The campaign was updated successfully!');
this.transitionTo('campaign', campaign);
}));
}
Campaigns and players have a many-to-many relationship. My problem arises if one of the saves fails. IE, I update all of the player records fine, but my update on the campaign fails for some reason. At this point I'm left with garbage data.
Any thoughts?