提交 4c0cddc9 编写于 作者: R Rafael Mendonça França

Bring back the valid_options class accessor

It is need in activerecord-deprecated_finders
上级 d0588a2e
require 'active_support/core_ext/module/attribute_accessors'
# This is the parent Association class which defines the variables # This is the parent Association class which defines the variables
# used by all associations. # used by all associations.
# #
...@@ -16,7 +18,10 @@ class << self ...@@ -16,7 +18,10 @@ class << self
end end
self.extensions = [] self.extensions = []
VALID_OPTIONS = [:class_name, :class, :foreign_key, :validate] # TODO: This class accessor is needed to make activerecord-deprecated_finders work.
# We can move it to a constant in 5.0.
cattr_accessor :valid_options, instance_accessor: false
self.valid_options = [:class_name, :class, :foreign_key, :validate]
def self.build(model, name, scope, options, &block) def self.build(model, name, scope, options, &block)
extension = define_extensions model, name, &block extension = define_extensions model, name, &block
...@@ -63,12 +68,12 @@ def self.macro ...@@ -63,12 +68,12 @@ def self.macro
raise NotImplementedError raise NotImplementedError
end end
def self.valid_options(options) def self.build_valid_options(options)
VALID_OPTIONS + Association.extensions.flat_map(&:valid_options) self.valid_options + Association.extensions.flat_map(&:valid_options)
end end
def self.validate_options(options) def self.validate_options(options)
options.assert_valid_keys(valid_options(options)) options.assert_valid_keys(build_valid_options(options))
end end
def self.define_extensions(model, name) def self.define_extensions(model, name)
......
...@@ -4,7 +4,7 @@ def self.macro ...@@ -4,7 +4,7 @@ def self.macro
:belongs_to :belongs_to
end end
def self.valid_options(options) def self.build_valid_options(options)
super + [:foreign_type, :polymorphic, :touch, :counter_cache] super + [:foreign_type, :polymorphic, :touch, :counter_cache]
end end
......
...@@ -7,7 +7,7 @@ class CollectionAssociation < Association #:nodoc: ...@@ -7,7 +7,7 @@ class CollectionAssociation < Association #:nodoc:
CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove] CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
def self.valid_options(options) def self.build_valid_options(options)
super + [:table_name, :before_add, super + [:table_name, :before_add,
:after_add, :before_remove, :after_remove, :extend] :after_add, :before_remove, :after_remove, :extend]
end end
......
...@@ -4,7 +4,7 @@ def self.macro ...@@ -4,7 +4,7 @@ def self.macro
:has_many :has_many
end end
def self.valid_options(options) def self.build_valid_options(options)
super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache] super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache]
end end
......
...@@ -4,7 +4,7 @@ def self.macro ...@@ -4,7 +4,7 @@ def self.macro
:has_one :has_one
end end
def self.valid_options(options) def self.build_valid_options(options)
valid = super + [:order, :as] valid = super + [:order, :as]
valid += [:through, :source, :source_type] if options[:through] valid += [:through, :source, :source_type] if options[:through]
valid valid
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module ActiveRecord::Associations::Builder module ActiveRecord::Associations::Builder
class SingularAssociation < Association #:nodoc: class SingularAssociation < Association #:nodoc:
def self.valid_options(options) def self.build_valid_options(options)
super + [:remote, :dependent, :primary_key, :inverse_of] super + [:remote, :dependent, :primary_key, :inverse_of]
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册