mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
reset @arel
when modifying a Relation in place.
/cc @tenderlove
This commit is contained in:
parent
10ed70185a
commit
1b7aa62b18
3 changed files with 18 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
* Reset the cache when modifying a Relation with cached Arel.
|
||||||
|
Additionally display a warning message to make the user aware.
|
||||||
|
|
||||||
|
*Yves Senn*
|
||||||
|
|
||||||
* PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
|
* PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
|
||||||
different spellings of timestamps are treated the same.
|
different spellings of timestamps are treated the same.
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
scope.references! reflection_scope.values[:references]
|
scope.references! reflection_scope.values[:references]
|
||||||
scope.order! reflection_scope.values[:order] if scope.eager_loading?
|
scope = scope.order reflection_scope.values[:order] if scope.eager_loading?
|
||||||
end
|
end
|
||||||
|
|
||||||
scope
|
scope
|
||||||
|
|
|
@ -64,6 +64,7 @@ module ActiveRecord
|
||||||
#
|
#
|
||||||
def #{name}_values=(values) # def select_values=(values)
|
def #{name}_values=(values) # def select_values=(values)
|
||||||
raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
|
raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
|
||||||
|
check_cached_relation
|
||||||
@values[:#{name}] = values # @values[:select] = values
|
@values[:#{name}] = values # @values[:select] = values
|
||||||
end # end
|
end # end
|
||||||
CODE
|
CODE
|
||||||
|
@ -81,11 +82,22 @@ module ActiveRecord
|
||||||
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
||||||
def #{name}_value=(value) # def readonly_value=(value)
|
def #{name}_value=(value) # def readonly_value=(value)
|
||||||
raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
|
raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
|
||||||
|
check_cached_relation
|
||||||
@values[:#{name}] = value # @values[:readonly] = value
|
@values[:#{name}] = value # @values[:readonly] = value
|
||||||
end # end
|
end # end
|
||||||
CODE
|
CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_cached_relation # :nodoc:
|
||||||
|
if defined?(@arel) && @arel
|
||||||
|
@arel = nil
|
||||||
|
ActiveSupport::Deprecation.warn <<-WARNING
|
||||||
|
Modifying already cached Relation. The cache will be reset.
|
||||||
|
Use a cloned Relation to prevent this warning.
|
||||||
|
WARNING
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_with_value # :nodoc:
|
def create_with_value # :nodoc:
|
||||||
@values[:create_with] || {}
|
@values[:create_with] || {}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue