-
Notifications
You must be signed in to change notification settings - Fork 198
Open
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch jsonapi-serializer@3.6.7
for the project I'm working on.
Currently I have to declare valueForRelationship for every relationship but many times the function must be applied to all entities so could be nice to have the possibility to declare a general valueForRelationship tha can be replaced per specific relationship.
Here is the diff that solved my problem:
diff --git a/node_modules/jsonapi-serializer/lib/deserializer-utils.js b/node_modules/jsonapi-serializer/lib/deserializer-utils.js
index 1265fd4..b63e3e6 100644
--- a/node_modules/jsonapi-serializer/lib/deserializer-utils.js
+++ b/node_modules/jsonapi-serializer/lib/deserializer-utils.js
@@ -14,9 +14,9 @@ module.exports = function (jsonapi, data, opts) {
}
function getValueForRelationship(relationshipData, included) {
- if (opts && relationshipData && opts[relationshipData.type]) {
- var valueForRelationshipFct = opts[relationshipData.type]
- .valueForRelationship;
+ if (opts && relationshipData && (opts[relationshipData.type] || opts.valueForRelationship)) {
+ var valueForRelationshipFct =
+ opts[relationshipData.type]?.valueForRelationship || opts.valueForRelationship;
return valueForRelationshipFct(relationshipData, included);
} else {
This issue body was partially generated by patch-package.
Metadata
Metadata
Assignees
Labels
No labels