diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-25 17:16:30 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-25 17:16:30 -0700 |
commit | b6a9c620aa58ac0b60ec3b18c380d296c0ec408d (patch) | |
tree | 0c86373926618f816e4ce5457bafc47b5ea3881d /activerecord/lib/active_record/relation | |
parent | 924127e21f13cadb6299a37df5bcd62a3b979ce7 (diff) | |
download | rails-b6a9c620aa58ac0b60ec3b18c380d296c0ec408d.tar.gz rails-b6a9c620aa58ac0b60ec3b18c380d296c0ec408d.tar.bz2 rails-b6a9c620aa58ac0b60ec3b18c380d296c0ec408d.zip |
`Relation#Merger` can merge all clause methods
This will make it easy to add `having_clause` and `join_clause` later.
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/merger.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 2f3ca539a7..82b38b6ec6 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -50,7 +50,8 @@ module ActiveRecord end NORMAL_VALUES = Relation::VALUE_METHODS - - [:joins, :where, :order, :reverse_order, :lock, :create_with, :reordering, :from] # :nodoc: + Relation::CLAUSE_METHODS - + [:joins, :order, :reverse_order, :lock, :create_with, :reordering, :from] # :nodoc: def normal_values NORMAL_VALUES @@ -74,6 +75,7 @@ module ActiveRecord merge_multi_values merge_single_values + merge_clauses merge_joins relation @@ -106,8 +108,6 @@ module ActiveRecord end def merge_multi_values - relation.where_clause = relation.where_clause.merge(other.where_clause) - if other.reordering_value # override any order specified in the original relation relation.reorder! other.order_values @@ -127,6 +127,14 @@ module ActiveRecord relation.create_with_value = (relation.create_with_value || {}).merge(other.create_with_value) end end + + def merge_clauses + CLAUSE_METHODS.each do |name| + clause = relation.send("#{name}_clause") + other_clause = other.send("#{name}_clause") + relation.send("#{name}_clause=", clause.merge(other_clause)) + end + end end end end |