aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-08-17 14:17:36 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-08-17 14:17:36 -0700
commit366eb7216edd4515d4c5491df6868dbf9fecd261 (patch)
tree6861e0a6cda6b6f3a0d9859ba190514b86d785fa /activerecord/lib/active_record
parent271beddd8929758802e11826297adf92e40cd4af (diff)
parentb127d86c1823d60a29191ecc3c21c97ee3ac502c (diff)
downloadrails-366eb7216edd4515d4c5491df6868dbf9fecd261.tar.gz
rails-366eb7216edd4515d4c5491df6868dbf9fecd261.tar.bz2
rails-366eb7216edd4515d4c5491df6868dbf9fecd261.zip
Merge pull request #7380 from ernie/fix-nomethoderror-on-non-attribute-equalities
Fix merge error when Equality LHS is non-attribute
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/merger.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 71aaedee1e..7531f22494 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -97,11 +97,14 @@ module ActiveRecord
merged_wheres = relation.where_values + values[:where]
unless relation.where_values.empty?
- # Remove duplicates, last one wins.
+ # Remove duplicate ARel attributes. Last one wins.
seen = Hash.new { |h,table| h[table] = {} }
merged_wheres = merged_wheres.reverse.reject { |w|
nuke = false
- if w.respond_to?(:operator) && w.operator == :==
+ # 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]