From bf6023a7b4fdbd60ddf6c92858c475f7fe41e8aa Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 29 Apr 2018 07:28:08 -0700 Subject: [PATCH] BUG: Rollback hasMany changesets sanely (#90) --- app/mixins/validation.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/mixins/validation.js b/app/mixins/validation.js index 0ad01ac..7e8c1cf 100644 --- a/app/mixins/validation.js +++ b/app/mixins/validation.js @@ -2,7 +2,6 @@ import Mixin from '@ember/object/mixin'; import { get } from '@ember/object'; import RSVP from 'rsvp'; const { keys } = Object; -const { isArray } = Array; export default Mixin.create({ validationSave(changesets, postSave) { @@ -55,9 +54,13 @@ export default Mixin.create({ for (const model of changesets[key]) { model.destroyRecord(); } - } else if (isArray(changesets[key])) { // hasMany - for (const { changeset } of changesets[key]) { - changeset.rollback(); + } else if (key === 'hasMany') { + const hasMany = changesets[key]; + for (const hasManyKey of keys(changesets[key])) { + const hasManyChangesets = hasMany[hasManyKey]; + for (const changeset of hasManyChangesets) { + changeset.rollback(); + } } } else { // single const changeset = changesets[key];