Open fran-worley opened 7 years ago
Hi @fran-worley. Can you post the exact arguments? Note also that the option is include
not included
:
http://www.rubydoc.info/gems/roar-jsonapi/Roar%2FJSON%2FJSONAPI%2FDocument:to_hash
Yup, that was poor github issue writing on my part, my render call is pretty simple:
# r.params["include"] == 'feature-image'
sites = Site.all
representer = Site::FullRepresenter.for_collection.new(sites)
response.write(representer.to_json(include: r.params["include"]))
@fran-worley if you're able to provide a reproduction (or at least the representers), that would help. Otherwise I'll try to reproduce this on the weekend.
Is this enough info? https://gist.github.com/fran-worley/39451042e02244d7efa9af3d9f952d58
@fran-worley I believe this is an issue with hyphenation: feature-image
relationship name vs. feature_image
method name, although I'm surprised it isn't affecting single representers as well.
I would suspect that if you were to rename feature-image
to feature
then it would work.
In any case, this is definitely a bug.
Hadn't thought of that, I'll run the same test with a non-hyphenated name and see what happens!
I've got the same issue when passing in a fields
option into to_json
. I've checked both dasherised and underscored names and it makes no difference.
Can confirm that relationships passed in via include:
don't work if they are hyphenated (like it would be for a JSONAPI request). We've got a "users" resource that has a "team-memberships" relationship on it. Passing in include=team_memberships
works, but include=team-memberships
doesn't.
I'll see if I can pin this down and send a PR, here's the workaround we're using for now:
normalized_include = (params[:include] || "").split(",").map(&:underscore)
render json: UserRepresenter.for_collection.prepare(users).to_json(include: normalized_include)
Hi @rohitpaulk :beers: thanks for posting your fix! The maintainer of this gem is presently lost without a trace, once he's back we might revisit this gem!
When I call
to_json()
on a representer from collection without specifying included records I get the full compound document complete with the included records.When I pass in an included option, all relationship attributes are rendered, but nothing is included at all.
When doing the same thing for a single representer I get the expected behaviour so I assume this issue is restricted to collections