diff --git a/lib/deserializer-utils.js b/lib/deserializer-utils.js index 1265fd4..e16f2c7 100644 --- a/lib/deserializer-utils.js +++ b/lib/deserializer-utils.js @@ -36,7 +36,7 @@ module.exports = function (jsonapi, data, opts) { if (included) { // To prevent circular references, check if the record type // has already been processed in this thread - if (ancestry.indexOf(included.type) > -1) { + if (ancestry.find((aIncluded) => aIncluded === included.type+':'+included.id)) { return Promise .all([extractAttributes(included)]) .then(function (results) { @@ -47,7 +47,7 @@ module.exports = function (jsonapi, data, opts) { } return Promise - .all([extractAttributes(included), extractRelationships(included, ancestry + ':' + included.type + included.id)]) + .all([extractAttributes(included), extractRelationships(included, [...ancestry, included.type + ':' + included.id])]) .then(function (results) { var attributes = results[0]; var relationships = results[1]; @@ -146,7 +146,7 @@ module.exports = function (jsonapi, data, opts) { this.perform = function () { return Promise - .all([extractAttributes(data), extractRelationships(data, data.type + data.id)]) + .all([extractAttributes(data), extractRelationships(data, [data.type + ':' + data.id])]) .then(function (results) { var attributes = results[0]; var relationships = results[1];