Skip to content

Commit e44f652

Browse files
authored
[BUGFIX] Set IDs on Record Data when mutating DS Model (#6775) (#6779)
1 parent 358c229 commit e44f652

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

packages/-ember-data/tests/unit/model-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ module('unit/model - Model', function(hooks) {
373373
assert.equal(idChange, 0);
374374
person._internalModel.setId('john');
375375
assert.equal(idChange, 1);
376+
let recordData = recordDataFor(person);
377+
assert.equal(
378+
recordData.getResourceIdentifier().id,
379+
'john',
380+
'new id should be set on the identifier on record data.'
381+
);
382+
assert.equal(recordData.id, 'john', 'new id should be correctly set on the record data itself.');
376383
assert.equal(person.get('id'), 'john', 'new id should be correctly set.');
377384
});
378385

packages/store/addon/-private/system/model/internal-model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,10 @@ export default class InternalModel {
13501350

13511351
if (didChange && id !== null) {
13521352
this.store.setRecordId(this.modelName, id, this.clientId);
1353+
// internal set of ID to get it to RecordData from DS.Model
1354+
if (this._recordData.__setId) {
1355+
this._recordData.__setId(id);
1356+
}
13531357
}
13541358

13551359
if (didChange && this.hasRecord) {

packages/store/addon/-private/system/model/record-data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ export default class RecordDataDefault implements RelationshipRecordData {
429429
}
430430
}
431431

432+
// internal set coming from the model
433+
__setId(id: string) {
434+
if (this.id !== id) {
435+
this.id = id;
436+
}
437+
}
438+
432439
getAttr(key: string): string {
433440
if (key in this._attributes) {
434441
return this._attributes[key];

packages/store/addon/-private/ts-interfaces/record-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ export default interface RecordData {
6565
isDeletionCommitted?(): boolean;
6666

6767
setIsDeleted?(isDeleted: boolean): void;
68+
69+
// Private and experimental
70+
__setId?(id: string): void;
6871
}

0 commit comments

Comments
 (0)