"Unknown key: :polymorphic" error on Rails master (6.1.0.alpha)
filippoliverani opened this issue · 1 comments
filippoliverani commented
When using current Rails master, acts_as_nested_set
fails on load with this error:
An error occurred while loading ./spec/models/users_spec.rb.
Failure/Error: belongs_to :parent, options
ArgumentError:
Unknown key: :polymorphic. Valid keys are: :class_name, :anonymous_class, :primary_key, :foreign_key, :dependent, :validate, :inverse_of, :autosave, :required, :touch, :counter_cache, :optional, :default
# ./lib/awesome_nested_set/awesome_nested_set.rb:105:in `acts_as_nested_set_relate_parent!'
# ./lib/awesome_nested_set/awesome_nested_set.rb:55:in `acts_as_nested_set'
# ./spec/support/models.rb:2:in `<class:Note>'
# ./spec/support/models.rb:1:in `<top (required)>'
# ./spec/spec_helper.rb:22:in `<top (required)>'
# ./spec/models/users_spec.rb:1:in `<top (required)>'
This is due to :polimorphic
key option being added only when set to true
since
osmaelo/rails@2c008d9
glaszig commented
this is an issue with rails which was fixed yesterday, see rails/rails#40879.
you can either use the 6-1-stable branch or try the following monkey patch:
# config/initializers/active_record.rb
module PolymorphicBelongsTo
def valid_options(options)
valid = super + [:polymorphic, :counter_cache, :optional, :default]
valid += [:foreign_type] if options[:polymorphic]
valid += [:ensuring_owner_was] if options[:dependent] == :destroy_async
valid
end
end
ActiveSupport.on_load :active_record do
ActiveRecord::Associations::Builder::BelongsTo.extend PolymorphicBelongsTo
end