BUG: Rollback hasMany changesets sanely (#90)

This commit is contained in:
Matthew Ryan Dillon 2018-04-29 07:28:08 -07:00 committed by GitHub
parent 6f6148df9d
commit bf6023a7b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,6 @@ import Mixin from '@ember/object/mixin';
import { get } from '@ember/object'; import { get } from '@ember/object';
import RSVP from 'rsvp'; import RSVP from 'rsvp';
const { keys } = Object; const { keys } = Object;
const { isArray } = Array;
export default Mixin.create({ export default Mixin.create({
validationSave(changesets, postSave) { validationSave(changesets, postSave) {
@ -55,9 +54,13 @@ export default Mixin.create({
for (const model of changesets[key]) { for (const model of changesets[key]) {
model.destroyRecord(); model.destroyRecord();
} }
} else if (isArray(changesets[key])) { // hasMany } else if (key === 'hasMany') {
for (const { changeset } of changesets[key]) { const hasMany = changesets[key];
changeset.rollback(); for (const hasManyKey of keys(changesets[key])) {
const hasManyChangesets = hasMany[hasManyKey];
for (const changeset of hasManyChangesets) {
changeset.rollback();
}
} }
} else { // single } else { // single
const changeset = changesets[key]; const changeset = changesets[key];