class ActiveRecord::Associations::Builder::Association
Constants
- DEPRECATED_OPTIONS
Public Instance Methods
initialize_with_deprecated_options(model, name, scope, options)
click to toggle source
# File lib/active_record/deprecated_finders/association_builder.rb, line 40 def initialize_with_deprecated_options(model, name, scope, options) options = scope if scope.is_a?(Hash) deprecated_options = options.slice(*DEPRECATED_OPTIONS) if scope.respond_to?(:call) && !deprecated_options.empty? raise ArgumentError, "Invalid mix of scope block and deprecated finder options on " \ "ActiveRecord association: #{model.name}.#{macro} :#{name}" end if scope.is_a?(Hash) if deprecated_options.empty? scope = nil else ActiveSupport::Deprecation.warn( "The following options in your #{model.name}.#{macro} :#{name} declaration are deprecated: " \ "#{deprecated_options.keys.map(&:inspect).join(',')}. Please use a scope block instead. " \ "For example, the following:\n" \ "\n" \ " has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'\n" \ "\n" \ "should be rewritten as the following:\n" \ "\n" \ " has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'\n" ) scope = DeprecatedOptionsProc.new(deprecated_options) options = options.except(*DEPRECATED_OPTIONS) end end initialize_without_deprecated_options(model, name, scope, options) end