aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/person.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-01-27 20:31:01 +0000
committerJon Leighton <j@jonathanleighton.com>2013-01-27 20:34:52 +0000
commitc8d889905dab071f1d8a166b25fa69cdd31dc176 (patch)
tree99703805e1fba618424676ae66cf78a30ce0a35c /activerecord/test/models/person.rb
parent78562309fc44a4bf28dcadd048e81545ccc716fb (diff)
downloadrails-c8d889905dab071f1d8a166b25fa69cdd31dc176.tar.gz
rails-c8d889905dab071f1d8a166b25fa69cdd31dc176.tar.bz2
rails-c8d889905dab071f1d8a166b25fa69cdd31dc176.zip
Prevent Relation#merge from collapsing wheres on the RHS
This caused a bug with the new associations implementation, because now association conditions are represented as Arel nodes internally right up to when the whole thing gets turned to SQL. In Rails 3.2, association conditions get turned to raw SQL early on, which prevents Relation#merge from interfering. The current implementation was buggy when a default_scope existed on the target model, since we would basically end up doing: default_scope.merge(association_scope) If default_scope contained a where(foo: 'a') and association_scope contained a where(foo: 'b').where(foo: 'c') then the merger would see that the same column is representated on both sides of the merge and collapse the wheres to all but the last: where(foo: 'c') Now, the RHS of the merge is left alone. Fixes #8990
Diffstat (limited to 'activerecord/test/models/person.rb')
-rw-r--r--activerecord/test/models/person.rb1
1 files changed, 1 insertions, 0 deletions
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index c602ca5eac..fa717ef8d6 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -15,6 +15,7 @@ class Person < ActiveRecord::Base
has_many :fixed_bad_references, -> { where :favourite => true }, :class_name => 'BadReference'
has_one :favourite_reference, -> { where 'favourite=?', true }, :class_name => 'Reference'
has_many :posts_with_comments_sorted_by_comment_id, -> { includes(:comments).order('comments.id') }, :through => :readers, :source => :post
+ has_many :first_posts, -> { where(id: [1, 2]) }, through: :readers
has_many :jobs, :through => :references
has_many :jobs_with_dependent_destroy, :source => :job, :through => :references, :dependent => :destroy