Skip to content

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

Description

@evaniainbrooks

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions