Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Set IDs on Record Data when mutating DS Model (#6775) #6780

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/-ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ module('unit/model - Model', function(hooks) {
assert.equal(idChange, 0);
person._internalModel.setId('john');
assert.equal(idChange, 1);
let recordData = recordDataFor(person);
assert.equal(
recordData.getResourceIdentifier().id,
'john',
'new id should be set on the identifier on record data.'
);
assert.equal(recordData.id, 'john', 'new id should be correctly set on the record data itself.');
assert.equal(person.get('id'), 'john', 'new id should be correctly set.');
});

Expand Down
7 changes: 7 additions & 0 deletions packages/record-data/addon/-private/record-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ export default class RecordDataDefault implements RelationshipRecordData {
}
}

// internal set coming from the model
__setId(id: string) {
if (this.id !== id) {
this.id = id;
}
}

getAttr(key: string): string {
if (key in this._attributes) {
return this._attributes[key];
Expand Down
4 changes: 4 additions & 0 deletions packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,10 @@ export default class InternalModel {

if (didChange && id !== null) {
this.store.setRecordId(this.modelName, id, this.clientId);
// internal set of ID to get it to RecordData from DS.Model
if (this._recordData.__setId) {
this._recordData.__setId(id);
}
}

if (didChange && this.hasRecord) {
Expand Down
3 changes: 3 additions & 0 deletions packages/store/addon/-private/ts-interfaces/record-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ export default interface RecordData {
isDeletionCommitted?(): boolean;

setIsDeleted?(isDeleted: boolean): void;

// Private and experimental
__setId?(id: string): void;
}