aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorErnie Miller <ernie@erniemiller.org>2012-08-19 08:02:09 -0400
committerErnie Miller <ernie@erniemiller.org>2012-08-19 08:06:31 -0400
commitbf80522be4d7ac521fa3c30d889afa68450a0bc2 (patch)
tree687385bd46b8a6d0761ea35fc82e9e6417c5eccb /activerecord/lib/active_record
parentf9fc26e8007d5e2936cf5374a8168b2c37273490 (diff)
downloadrails-bf80522be4d7ac521fa3c30d889afa68450a0bc2.tar.gz
rails-bf80522be4d7ac521fa3c30d889afa68450a0bc2.tar.bz2
rails-bf80522be4d7ac521fa3c30d889afa68450a0bc2.zip
Fix "last equality wins" logic in relation merge
This is a real fix (as compared to the band-aid in b127d86c), which uses the recently-added equality methods for ARel nodes. It has the side benefit of simplifying the merge code a bit.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/merger.rb15
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 7531f22494..e5b50673da 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -97,18 +97,13 @@ module ActiveRecord
merged_wheres = relation.where_values + values[:where]
unless relation.where_values.empty?
- # Remove duplicate ARel attributes. Last one wins.
- seen = Hash.new { |h,table| h[table] = {} }
+ # Remove equalities with duplicated left-hand. Last one wins.
+ seen = {}
merged_wheres = merged_wheres.reverse.reject { |w|
nuke = false
- # We might have non-attributes on the left side of equality nodes,
- # so we need to make sure they quack like an attribute.
- if w.respond_to?(:operator) && w.operator == :== &&
- w.left.respond_to?(:relation)
- name = w.left.name
- table = w.left.relation.name
- nuke = seen[table][name]
- seen[table][name] = true
+ if w.respond_to?(:operator) && w.operator == :==
+ nuke = seen[w.left]
+ seen[w.left] = true
end
nuke
}.reverse