jsonapi-serializer icon indicating copy to clipboard operation
jsonapi-serializer copied to clipboard

fix(#192): `self` links not serialized without a `related` link

Open sarus opened this issue 5 years ago • 0 comments

This PR is to fix a regression introduced by https://github.com/SeyZ/jsonapi-serializer/commit/3d776ef46b3cb150d09c9d7efc209a5a7ecc7bc0 and covered in issue #192

The original commit was meant to ignore relationshipLinks that return null but the commit did not take into account the fact that relationshipLinks can include a self and/or related link. As a result, if there was a self link but no related link the original commit would not display the relationshipLinks.

This PR fixes this by modifying the getLinks method to not return keys which evaluate to null (switch from map to reduce). Null relationship links will not be returned as intended by the original commit but if a non-null relationship link exists it will still be displayed (i.e., you can have self links again). The PR also adds additional test coverage to cover all permutations of self and related links being null.

Please consider merging this PR into master to fix a fairly large regression introduced in 3.6.1.

Thank you!

sarus avatar Feb 14 '20 05:02 sarus