Netflix / fast_jsonapi

No Longer Maintained - A lightning fast JSON:API serializer for Ruby Objects.
Apache License 2.0
5.07k stars 425 forks source link

`relationships` remains empty when using sparse fieldsets (`fields` in query) #439

Open everlast240 opened 4 years ago

everlast240 commented 4 years ago

When include is used to include related documents (compound document) and you also have sparse fieldsets (you filter returned attributes with the fields parameter), the relationships attribute of the root resource remains empty. This is rather confusing because this way you have no way how to link the root resources (if multiple) to their corresponding included related resources.. I've identified the issue to come from here: https://github.com/Netflix/fast_jsonapi/blob/master/lib/fast_jsonapi/serialization_core.rb#L54 It works as expected if that line is commented out... Now I see a related issue: https://github.com/Netflix/fast_jsonapi/issues/304 - according to which there is a way to trick / work around this:

you must specify associations in the fields option if you want fast_jsonapi to populate the relationships hash appropriately

But I'm not sure if this is the JSONAPI v1 compliant way ...

So, if this is not considered a bug, maybe some documentation improvements should make this clear.

everlast240 commented 4 years ago

See also: https://github.com/Netflix/fast_jsonapi/commit/a363c90b#commitcomment-34658281

kapilnarula commented 4 years ago

It seems Netflix has abandoned this project. The community created a new fork to continue supporting this project. Please refer https://github.com/fast-jsonapi/fast_jsonapi