diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-03-23 15:27:00 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-03-25 13:03:30 -0300 |
commit | 90a4709601873583d32c422c3a6422ef56bbc81b (patch) | |
tree | 48d03b96a320169ea1d4f8b7936b5e52e7eeea3f | |
parent | e260d5fbcfd1e843c849826a184c3fb76f08f980 (diff) | |
download | rails-90a4709601873583d32c422c3a6422ef56bbc81b.tar.gz rails-90a4709601873583d32c422c3a6422ef56bbc81b.tar.bz2 rails-90a4709601873583d32c422c3a6422ef56bbc81b.zip |
Refactor relation merging to create just one relation and then assign values, instead of creating multiple relation objects.
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a18380f01c..2841ff1239 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -4,30 +4,14 @@ module ActiveRecord merged_relation = clone return merged_relation unless r - merged_relation = merged_relation.eager_load(r.eager_load_values).preload(r.preload_values).includes(r.includes_values) - - merged_relation.readonly_value = r.readonly_value unless r.readonly_value.nil? - merged_relation.limit_value = r.limit_value if r.limit_value.present? - merged_relation.lock_value = r.lock_value unless merged_relation.lock_value - merged_relation.offset_value = r.offset_value if r.offset_value.present? - - merged_relation = merged_relation. - joins(r.joins_values). - group(r.group_values). - select(r.select_values). - from(r.from_value). - having(r.having_values) - - merged_relation.order_values = r.order_values if r.order_values.present? - - merged_relation.create_with_value = @create_with_value - - if @create_with_value && r.create_with_value - merged_relation.create_with_value = @create_with_value.merge(r.create_with_value) - else - merged_relation.create_with_value = r.create_with_value || @create_with_value + (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method| + unless (value = r.send(:"#{method}_values")).blank? + merged_relation.send(:"#{method}_values=", value) + end end + merged_relation = merged_relation.joins(r.joins_values) + merged_wheres = @where_values r.where_values.each do |w| @@ -40,6 +24,14 @@ module ActiveRecord merged_relation.where_values = merged_wheres + ActiveRecord::Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method| + unless (value = r.send(:"#{method}_value")).nil? + merged_relation.send(:"#{method}_value=", value) + end + end + + merged_relation.lock_value = r.lock_value unless merged_relation.lock_value + merged_relation end |