Skip to content

Commit 546d70d

Browse files
Merge pull request #381 from VincentMolinie/fix/has-dirty-attributes-property-reset
fix(hasDirtyAttributes): fix hasDirtyAttributes when resetting a property
2 parents 049946f + 9de7bbd commit 546d70d

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

addon/record-data.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,11 @@ export default class FragmentRecordData extends RecordData {
302302
}
303303

304304
hasChangedAttributes() {
305-
return (
306-
this.__attributes !== null && Object.keys(this.__attributes).length > 0
307-
);
305+
return super.hasChangedAttributes() ||
306+
this.fragmentNames.some(fragmentName => {
307+
const fragment = this.getFragmentWithoutCreating(fragmentName);
308+
return fragment && fragment.hasDirtyAttributes;
309+
});
308310
}
309311

310312
resetRecord() {

tests/integration/dependent_state_test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,4 +1019,40 @@ module('integration - Dependent State', function(hooks) {
10191019
});
10201020
});
10211021
});
1022+
1023+
test('updating a fragment and a property then resetting the property', function(assert) {
1024+
run(() => {
1025+
pushPerson(1);
1026+
1027+
return store.find('person', 1).then(person => {
1028+
assert.ok(
1029+
!person.get('hasDirtyAttributes'),
1030+
'person record is not dirty'
1031+
);
1032+
1033+
person.name.set('first', 'Another firstname');
1034+
assert.ok(
1035+
person.get('hasDirtyAttributes'),
1036+
'person record is dirty'
1037+
);
1038+
1039+
const oldTitle = person.title;
1040+
person.set('title', 'New title');
1041+
assert.ok(
1042+
person.get('hasDirtyAttributes'),
1043+
'person record is dirty'
1044+
);
1045+
1046+
person.set('title', oldTitle);
1047+
assert.ok(
1048+
person.name.get('hasDirtyAttributes'),
1049+
'fragment name is dirty'
1050+
);
1051+
assert.ok(
1052+
person.get('hasDirtyAttributes'),
1053+
'person record is dirty'
1054+
);
1055+
});
1056+
});
1057+
});
10221058
});

0 commit comments

Comments
 (0)