From 0a1ff1a14ffcc96204ba1d391207d13e68cda8b0 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 29 Dec 2009 15:28:40 +0530 Subject: [PATCH] Rewrite Relation#readonly, eager_load, preload using Object#tap --- activerecord/lib/active_record/relation.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index e40432bf6a..72e7c234eb 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -33,21 +33,15 @@ module ActiveRecord alias :& :merge def preload(*associations) - relation = spawn - relation.preload_associations += Array.wrap(associations) - relation + spawn.tap {|r| r.preload_associations += Array.wrap(associations) } end def eager_load(*associations) - relation = spawn - relation.eager_load_associations += Array.wrap(associations) - relation + spawn.tap {|r| r.eager_load_associations += Array.wrap(associations) } end def readonly(status = true) - relation = spawn - relation.readonly = status - relation + spawn.tap {|r| r.readonly = status } end def select(selects) @@ -135,9 +129,7 @@ module ActiveRecord @relation.join(join, join_type) end - relation = spawn(join_relation) - relation.readonly = true - relation + spawn(join_relation) { |r| r.readonly = true } end def where(*args)