Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When mixed into AR model, and AR association with accepts_nested_attributes_for has a reject_if proc, the proc is never invoked #195

Open
evaniainbrooks opened this issue Nov 30, 2024 · 0 comments

Comments

@evaniainbrooks
Copy link
Contributor

Minimal example

class Product < ActiveRecord::Base
   include NestedAttributes

   belongs_to :store
   accepts_nested_attributes_for :store, reject_if: ->(_) { raise "This never raises" }
end

product = Product.new
product.update(store_attributes: { bicycles: {} })

I traced the issue down to the call_reject_if method redefinition inside NestedAttributes mix-in here:

https://github.com/DmitryTsepelev/store_model/blob/master/lib/store_model/nested_attributes.rb#L141

The parameters don't match the method parameters inside the ActiveRecord mix-in:

https://github.com/rails/rails/blob/dd8f7185faeca6ee968a6e9367f6d8601a83b8db/activerecord/lib/active_record/nested_attributes.rb#L598

Renaming the method in this gem to something else, like call_store_model_reject_if, fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant