aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb24
1 files changed, 13 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index 648a02f1cc..d761bd3ea6 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -28,17 +28,19 @@ module ActiveRecord
merged_wheres = @where_values + r.where_values
- # Remove duplicates, last one wins.
- seen = {}
- merged_wheres = merged_wheres.reverse.reject { |w|
- nuke = false
- if w.respond_to?(:operator) && w.operator == :==
- name = w.left.name
- nuke = seen[name]
- seen[name] = true
- end
- nuke
- }.reverse
+ unless @where_values.empty?
+ # Remove duplicates, last one wins.
+ seen = {}
+ merged_wheres = merged_wheres.reverse.reject { |w|
+ nuke = false
+ if w.respond_to?(:operator) && w.operator == :==
+ name = w.left.name
+ nuke = seen[name]
+ seen[name] = true
+ end
+ nuke
+ }.reverse
+ end
merged_relation.where_values = merged_wheres