提交 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
# used by all associations.
#
......@@ -16,7 +18,10 @@ class << self
end
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)
extension = define_extensions model, name, &block
......@@ -63,12 +68,12 @@ def self.macro
raise NotImplementedError
end
def self.valid_options(options)
VALID_OPTIONS + Association.extensions.flat_map(&:valid_options)
def self.build_valid_options(options)
self.valid_options + Association.extensions.flat_map(&:valid_options)
end
def self.validate_options(options)
options.assert_valid_keys(valid_options(options))
options.assert_valid_keys(build_valid_options(options))
end
def self.define_extensions(model, name)
......
......@@ -4,7 +4,7 @@ def self.macro
:belongs_to
end
def self.valid_options(options)
def self.build_valid_options(options)
super + [:foreign_type, :polymorphic, :touch, :counter_cache]
end
......
......@@ -7,7 +7,7 @@ class CollectionAssociation < Association #:nodoc:
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,
:after_add, :before_remove, :after_remove, :extend]
end
......
......@@ -4,7 +4,7 @@ def self.macro
:has_many
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]
end
......
......@@ -4,7 +4,7 @@ def self.macro
:has_one
end
def self.valid_options(options)
def self.build_valid_options(options)
valid = super + [:order, :as]
valid += [:through, :source, :source_type] if options[:through]
valid
......
......@@ -2,7 +2,7 @@
module ActiveRecord::Associations::Builder
class SingularAssociation < Association #:nodoc:
def self.valid_options(options)
def self.build_valid_options(options)
super + [:remote, :dependent, :primary_key, :inverse_of]
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册