diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2013-05-08 14:20:06 -0400 |
---|---|---|
committer | Neeraj Singh <neerajdotname@gmail.com> | 2013-05-08 15:21:52 -0400 |
commit | fdba949b47154f43aa8d0cce5177a75080f47836 (patch) | |
tree | b9ceb5556d6563cbf7b76cc221f0202e8ad2056f /activerecord/lib/active_record/relation/merger.rb | |
parent | d77c64590a075284343aa6cf200f2a9c2e160a86 (diff) | |
download | rails-fdba949b47154f43aa8d0cce5177a75080f47836.tar.gz rails-fdba949b47154f43aa8d0cce5177a75080f47836.tar.bz2 rails-fdba949b47154f43aa8d0cce5177a75080f47836.zip |
extracted piece of code into a method
In order to fix #10421 I need to enable merge to take an option
so that relations could be merged without making the last where
condition to win.
That fix would forever reside in 4-0-stable branch and would not be
merged to master since using scope without lambda has been deprecated.
In this commit I have extracted code into a method and I think it
makes code look better. Hence the request to merge it in both
master and 4-0-stable.
If there is any concern then this code can be merged only in
4-0-stable and that would be fine too.
Diffstat (limited to 'activerecord/lib/active_record/relation/merger.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/merger.rb | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 936b83261e..bda7a76330 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -139,21 +139,20 @@ module ActiveRecord if values[:where].empty? || relation.where_values.empty? relation.where_values + values[:where] else - # Remove equalities from the existing relation with a LHS which is - # present in the relation being merged in. + sanitized_wheres + values[:where] + end + end - seen = Set.new - values[:where].each { |w| - if w.respond_to?(:operator) && w.operator == :== - seen << w.left - end - } + # Remove equalities from the existing relation with a LHS which is + # present in the relation being merged in. + def sanitized_wheres + seen = Set.new + values[:where].each do |w| + seen << w.left if w.respond_to?(:operator) && w.operator == :== + end - relation.where_values.reject { |w| - w.respond_to?(:operator) && - w.operator == :== && - seen.include?(w.left) - } + values[:where] + relation.where_values.reject do |w| + w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) end end end |