diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-02 22:43:40 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-02 22:43:40 +0530 |
commit | 32b48bf419eb22514be9a75981b9b0cf51a973a0 (patch) | |
tree | 142667fdc93ea79e83dcae6fb8c38b1e7d80bf86 /activerecord/lib/active_record | |
parent | f1acf1cc74bb9e847a4d27e97630d1b685764a93 (diff) | |
download | rails-32b48bf419eb22514be9a75981b9b0cf51a973a0.tar.gz rails-32b48bf419eb22514be9a75981b9b0cf51a973a0.tar.bz2 rails-32b48bf419eb22514be9a75981b9b0cf51a973a0.zip |
Use arel predicates instead of strings wherever possible when merging relations
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 44e2061efa..6eb1d907e6 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -18,19 +18,18 @@ module ActiveRecord def merge(r) raise ArgumentError, "Cannot merge a #{r.klass.name} relation with #{@klass.name} relation" if r.klass != @klass - merged_relation = spawn(table) + merged_relation = spawn(table).eager_load(r.eager_load_associations).preload(r.preload_associations) + merged_relation.readonly = r.readonly - [self, r].each do |r| + [self.relation, r.relation].each do |arel| merged_relation = merged_relation. - joins(r.relation.joins(r.relation)). - group(r.send(:group_clauses).join(', ')). - order(r.send(:order_clauses).join(', ')). - limit(r.taken). - offset(r.skipped). - select(r.send(:select_clauses).join(', ')). - eager_load(r.eager_load_associations). - preload(r.preload_associations). - from(r.send(:sources).present? ? r.send(:from_clauses) : nil) + joins(arel.joins(arel)). + group(arel.groupings). + order(arel.send(:order_clauses).join(', ')). + limit(arel.taken). + offset(arel.skipped). + select(arel.send(:select_clauses)). + from(arel.sources) end merged_wheres = @relation.wheres |