Skip to content

Commit 4c0cddc

Browse files
committed
Bring back the valid_options class accessor
It is need in activerecord-deprecated_finders
1 parent d0588a2 commit 4c0cddc

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

activerecord/lib/active_record/associations/builder/association.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'active_support/core_ext/module/attribute_accessors'
2+
13
# This is the parent Association class which defines the variables
24
# used by all associations.
35
#
@@ -16,7 +18,10 @@ class << self
1618
end
1719
self.extensions = []
1820

19-
VALID_OPTIONS = [:class_name, :class, :foreign_key, :validate]
21+
# TODO: This class accessor is needed to make activerecord-deprecated_finders work.
22+
# We can move it to a constant in 5.0.
23+
cattr_accessor :valid_options, instance_accessor: false
24+
self.valid_options = [:class_name, :class, :foreign_key, :validate]
2025

2126
def self.build(model, name, scope, options, &block)
2227
extension = define_extensions model, name, &block
@@ -63,12 +68,12 @@ def self.macro
6368
raise NotImplementedError
6469
end
6570

66-
def self.valid_options(options)
67-
VALID_OPTIONS + Association.extensions.flat_map(&:valid_options)
71+
def self.build_valid_options(options)
72+
self.valid_options + Association.extensions.flat_map(&:valid_options)
6873
end
6974

7075
def self.validate_options(options)
71-
options.assert_valid_keys(valid_options(options))
76+
options.assert_valid_keys(build_valid_options(options))
7277
end
7378

7479
def self.define_extensions(model, name)

activerecord/lib/active_record/associations/builder/belongs_to.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def self.macro
44
:belongs_to
55
end
66

7-
def self.valid_options(options)
7+
def self.build_valid_options(options)
88
super + [:foreign_type, :polymorphic, :touch, :counter_cache]
99
end
1010

activerecord/lib/active_record/associations/builder/collection_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CollectionAssociation < Association #:nodoc:
77

88
CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
99

10-
def self.valid_options(options)
10+
def self.build_valid_options(options)
1111
super + [:table_name, :before_add,
1212
:after_add, :before_remove, :after_remove, :extend]
1313
end

activerecord/lib/active_record/associations/builder/has_many.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def self.macro
44
:has_many
55
end
66

7-
def self.valid_options(options)
7+
def self.build_valid_options(options)
88
super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache]
99
end
1010

activerecord/lib/active_record/associations/builder/has_one.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def self.macro
44
:has_one
55
end
66

7-
def self.valid_options(options)
7+
def self.build_valid_options(options)
88
valid = super + [:order, :as]
99
valid += [:through, :source, :source_type] if options[:through]
1010
valid

activerecord/lib/active_record/associations/builder/singular_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module ActiveRecord::Associations::Builder
44
class SingularAssociation < Association #:nodoc:
5-
def self.valid_options(options)
5+
def self.build_valid_options(options)
66
super + [:remote, :dependent, :primary_key, :inverse_of]
77
end
88

0 commit comments

Comments
 (0)