fast_jsonapi
fast_jsonapi copied to clipboard
Nested includes not working as documented
Per the documentation, one should be able to specify nested relationships in the include key and only return the last relationship in dot notation. However, this is not working like that. Using the RSpec contexts:
options = {}
options[:include] = [:"actors.awards"]
MovieSerializer.new(movie, options).serializable_hash
This should only include awards, but it includes actors and awards.
Personally, I prefer this, but is it the intended behavior?
The intended behaviour was to only serialize the last relationship - I'm on the fence as to the current behaviour - it's not precise, which I generally don't like, but I've taken advantage of the syntax
ActiveModel::Serializers follows the current convention, of serializing all relationships in the dotted chain, but I understand both use cases for sure. Either way, I think it should be adjusted to match the intended behavior, or documentation should reflect the current implementation.
now that I think of it, it would be tough to just serialize the end chain, as we need to walk through each serializer's instance - far easier to adjust the documentation, and there's something to be said for api consistency with AMS
If you do not serialize all the chain - client will not be able to restore the chain in general use case
I think making docs more clear about this would be enough
I think if you stop including the whole chain it's not jsonapi anymore. The spec is pretty explicit about full linkage. The example in the docs linked to above has some redundant keys that could be removed, also in the spec.
http://jsonapi.org/format/#document-compound-documents http://jsonapi.org/format/#fetching-includes
I have a Trip model that has_many Ticket s. Both Trip and Ticket has_many Node s.
Right now options[:include] = [:'tickets.nodes'] includes ticket nodes as well as trip nodes, while I was expecting only ticket nodes to be included.
I think options[:include] = [:'tickets.nodes'] should only include ticket nodes.
Other serializers implement it as it is here (e.g. https://github.com/jsonapi-rb/jsonapi-serializable) with all nodes included. I'd stick with that and update the documentation. As @nruth says, it's in the spec.
Can this be closed per @nruth's comment?
@dpikt I think documentation needs to be clarified then it should be good to go!