Skip to content
Browse files

Make sure the relations are always immutable

  • Loading branch information...
1 parent 187fbe5 commit 284d186cf4e055cefb2f8482d016e3bd09e9c341 @lifo lifo committed
Showing with 5 additions and 8 deletions.
  1. +5 −8 activerecord/lib/active_record/relation.rb
View
13 activerecord/lib/active_record/relation.rb
@@ -12,18 +12,15 @@ def initialize(klass, relation, readonly = false, preload = [], eager_load = [])
end
def preload(associations)
- @associations_to_preload << associations
- self
+ create_new_relation(@relation, @readonly, @associations_to_preload + Array.wrap(associations))
end
def eager_load(associations)
- @eager_load_associations += Array.wrap(associations)
- self
+ create_new_relation(@relation, @readonly, @associations_to_preload, @eager_load_associations + Array.wrap(associations))
end
def readonly
- @readonly = true
- self
+ create_new_relation(@relation, true)
end
def to_a
@@ -124,8 +121,8 @@ def method_missing(method, *args, &block)
end
end
- def create_new_relation(relation)
- Relation.new(@klass, relation, @readonly, @associations_to_preload, @eager_load_associations)
+ def create_new_relation(relation, readonly = @readonly, preload = @associations_to_preload, eager_load = @eager_load_associations)
+ Relation.new(@klass, relation, readonly, preload, eager_load)
end
end

0 comments on commit 284d186

Please sign in to comment.
Something went wrong with that request. Please try again.