hangar icon indicating copy to clipboard operation
hangar copied to clipboard

Request with include option, not parsing correctly

Open ristovskiv opened this issue 7 years ago • 0 comments

Hey guys when using the include param for including an association in the response along with some specific fields, with the current implementation I think it is a bit buggy and it doesn't parse the response in the intended way. I've posted a PR where the spec for that feature is more precise, and that spec fails. The reason behind this is using as_json on the strong params of :include option in the json render which will transform the strong params object into a Hash object with all its keys deeply converted into strings. Because of that, since we are using as_json on the Model and we have a Hash with keys as strings under the :include key, regardless of the version of rails it will include the associated model with all of its attributes. https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serializers/json.rb#L89-L102 https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serialization.rb#L130

ristovskiv avatar Jul 26 '18 09:07 ristovskiv