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

Renders relationship objects even where's no data on included #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andersonmarcelino
Copy link

@andersonmarcelino andersonmarcelino commented Nov 3, 2023

Issue opened with the description of error: #253

When the deserializer receives a relationship without included data, they just ignore it, but sometimes, for performance uses, we just need the object id, and dont want to include the entire object on response data. This solution add an object with just an in on the output of deserializer.

@andersonmarcelino andersonmarcelino marked this pull request as ready for review November 3, 2023 16:54
@andersonmarcelino andersonmarcelino changed the title Renders relationship objects even wheres no data on included Renders relationship objects even where's no data on included Nov 3, 2023
@martinezguillaume
Copy link

martinezguillaume commented Jun 13, 2024

this pr is highly needed & useful ! Is there any way to get it merged ? :)

the file jsonapi-serializer+3.6.9.patch for those who need it

diff --git a/node_modules/jsonapi-serializer/lib/deserializer-utils.js b/node_modules/jsonapi-serializer/lib/deserializer-utils.js
index 1265fd4..480ab81 100644
--- a/node_modules/jsonapi-serializer/lib/deserializer-utils.js
+++ b/node_modules/jsonapi-serializer/lib/deserializer-utils.js
@@ -26,7 +26,7 @@ module.exports = function (jsonapi, data, opts) {
 
   function findIncluded(relationshipData, ancestry) {
     return new Promise(function (resolve) {
-      if (!jsonapi.included || !relationshipData) { resolve(null); }
+      if (!relationshipData) { resolve(null); }
 
       var included = _find(jsonapi.included, {
         id: relationshipData.id,
@@ -54,7 +54,7 @@ module.exports = function (jsonapi, data, opts) {
             resolve(_extend(attributes, relationships));
           });
       } else {
-        return resolve(null);
+        return resolve({ id: relationshipData.id });
       }
     });
   }


var included = _find(jsonapi.included, {
var included = _find(jsonapi.included || [], {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is useless, you can call _find with null or undefined 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants