@@ -62,15 +62,14 @@ def not(opts, *rest)
62
62
63
63
Relation ::MULTI_VALUE_METHODS . each do |name |
64
64
class_eval <<-CODE , __FILE__ , __LINE__ + 1
65
- def #{ name } _values # def select_values
66
- @values[:#{ name } ] || [] # @values[:select] || []
67
- end # end
68
- #
69
- def #{ name } _values=(values) # def select_values=(values)
70
- raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
71
- check_cached_relation
72
- @values[:#{ name } ] = values # @values[:select] = values
73
- end # end
65
+ def #{ name } _values # def select_values
66
+ @values[:#{ name } ] || [] # @values[:select] || []
67
+ end # end
68
+ #
69
+ def #{ name } _values=(values) # def select_values=(values)
70
+ assert_mutability! # assert_mutability!
71
+ @values[:#{ name } ] = values # @values[:select] = values
72
+ end # end
74
73
CODE
75
74
end
76
75
@@ -85,23 +84,12 @@ def #{name}_value # def readonly_value
85
84
Relation ::SINGLE_VALUE_METHODS . each do |name |
86
85
class_eval <<-CODE , __FILE__ , __LINE__ + 1
87
86
def #{ name } _value=(value) # def readonly_value=(value)
88
- raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
89
- check_cached_relation
87
+ assert_mutability! # assert_mutability!
90
88
@values[:#{ name } ] = value # @values[:readonly] = value
91
89
end # end
92
90
CODE
93
91
end
94
92
95
- def check_cached_relation # :nodoc:
96
- if defined? ( @arel ) && @arel
97
- @arel = nil
98
- ActiveSupport ::Deprecation . warn ( <<-MSG . squish )
99
- Modifying already cached Relation. The cache will be reset. Use a
100
- cloned Relation to prevent this warning.
101
- MSG
102
- end
103
- end
104
-
105
93
def create_with_value # :nodoc:
106
94
@values [ :create_with ] || { }
107
95
end
@@ -857,6 +845,11 @@ def arel # :nodoc:
857
845
858
846
private
859
847
848
+ def assert_mutability!
849
+ raise ImmutableRelation if @loaded
850
+ raise ImmutableRelation if defined? ( @arel ) && @arel
851
+ end
852
+
860
853
def build_arel
861
854
arel = Arel ::SelectManager . new ( table )
862
855
0 commit comments