Ignore belongs_to relations when parsing params#284
Ignore belongs_to relations when parsing params#284kindrowboat wants to merge 1 commit intoremi:masterfrom
Conversation
|
Great to see this! Has been bugging me as well :) For me the class Recipe
include Her::Model
has_many :steps
accepts_nested_attributes_for :steps
end
class Step
include Her::Model
belongs_to :recipe
endresults in something like {
"recipe"=>
{
"steps"=> [{"id"=>"1","recipe"=>"#<Recipe:0x007fc2e5deebd0>"}]
}
}Haven't found the cause myself yet, maybe something deeper going on...? |
|
@dturnerTS, unless I misunderstood, this is not the same situation as #261, because |
|
@aauthor, @dturnerTS Sorry about that, while writing the failing spec I actually realised the problem was in fact that The problem is indeed #261 ! Thanks for pointing me in the right direction 😁 For reference, here is the failing spec showing that particular problem: https://github.com/balvig/her/commit/be7ffd77e7585cb8ce018b836a9465f9c73af382 |
…params Ignore belongs_to relations when parsing params
By convention,
belongs_torelations are not parsed into the params; however in some contexts, thebelongs_to:data_keymight be set inattributes. The#to_paramsmethod does not attempt to parse these attributes, and so, one ends up with a JSON body containing:{ ... "some_belongs_to_key":"#<SomeBelongsToKlass:0x00000005dfd388>", ... }This is extra noise through the pipe at best, and in our use, cause the resource server to complain and 400/500.
This fix, strips out any
belongs_todata_keyin theattributeswhen parsing params.