highrise icon indicating copy to clipboard operation
highrise copied to clipboard

422 Unprocessable Entity on update due to nested models

Open reidab opened this issue 13 years ago • 2 comments

When updating a Deal, if a nested Party model is included in the post body, a 422 error is being returned.

According to this message, Highrise has recently started returning 422 errors in cases where it hadn't before.

Testing manually, I found this to work fine

<deal>
  <name>Deal</name>
</deal>

While this 422'd

<deal>
  <name>Deal</name>
  <party>
  </party>
</deal>

I got around it for my immediate needs by monkey-patching the Deal class as follows, but there's surely a more elegant solution to be had.

module Highrise
  class Deal
    def encode_with_nested_attribute_exclusion(options={})
      encode_without_nested_attribute_exclusion({:except => [:party, :parties]}.merge(options))
    end
    alias_method_chain :encode, :nested_attribute_exclusion
  end
end

reidab avatar Jan 31 '12 10:01 reidab

Can you write a test to address this issue?

tapajos avatar Jun 02 '12 20:06 tapajos

I had the same issue, thanks for the monkey-patch!

michaelkoper avatar Nov 25 '15 10:11 michaelkoper