diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-30 13:31:00 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-30 13:31:00 -0800 |
commit | 8998aea4b751ba8d9a6362f8cc11db5cf46a71ee (patch) | |
tree | 65a86a0a796d4d271e48bda4a2aaa690aca99216 | |
parent | b6848b6491b75d69c0e1ceaa6a66d86305124d24 (diff) | |
download | rails-8998aea4b751ba8d9a6362f8cc11db5cf46a71ee.tar.gz rails-8998aea4b751ba8d9a6362f8cc11db5cf46a71ee.tar.bz2 rails-8998aea4b751ba8d9a6362f8cc11db5cf46a71ee.zip |
making relationship merge cheaper
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a61a3bd41c..5acf3ec83a 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -3,10 +3,11 @@ require 'active_support/core_ext/object/blank' module ActiveRecord module SpawnMethods def merge(r) - merged_relation = clone - return merged_relation unless r + return self unless r return to_a & r if r.is_a?(Array) + merged_relation = clone + Relation::ASSOCIATION_METHODS.each do |method| value = r.send(:"#{method}_values") @@ -24,7 +25,7 @@ module ActiveRecord merged_relation.send(:"#{method}_values=", merged_relation.send(:"#{method}_values") + value) if value.present? end - merged_relation = merged_relation.joins(r.joins_values) + merged_relation.joins_values += r.joins_values merged_wheres = @where_values + r.where_values |