Skip to content

Commit

Permalink
Fix check for new records in JSONAPISerializer.serializeHasMany (#8794)
Browse files Browse the repository at this point in the history
Use `!Snapshot.isNew` instead of `Snapshot.record && !Snapshot.record.isNew` to avoid the access to `record`. Accessing `record` creates an entry in `instanceCache.record` which causes the `hasRecord` checks in `Snapshot` to return true. This results in an error when serializing associated records via hasMany that have not been loaded.
  • Loading branch information
dagroe committed Aug 26, 2023
1 parent 439b883 commit 03498a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/serializer/src/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ const JSONAPISerializer = JSONSerializer.extend({
}

// only serialize has many relationships that are not new
let nonNewHasMany = hasMany.filter((item) => item.record && !item.record.isNew);
let nonNewHasMany = hasMany.filter((item) => !item.isNew);
let data = new Array(nonNewHasMany.length);

for (let i = 0; i < nonNewHasMany.length; i++) {
Expand Down

0 comments on commit 03498a7

Please sign in to comment.