提交 284d186c 编写于 作者: P Pratik Naik

Make sure the relations are always immutable

上级 187fbe5c
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册