diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-09-16 13:45:25 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-09-16 13:45:25 -0300 |
commit | ae297710dd526a95bae99bd143e2bb185466cc23 (patch) | |
tree | 0114e070dbd19a6efd8dc19f611b1816bbd4f643 /activerecord/test | |
parent | 678fdda54f391a7fec92e2c0d2a94b6e889c220c (diff) | |
parent | fbbb6c87fd5e8fcd913c0dbf518024edd7538072 (diff) | |
download | rails-ae297710dd526a95bae99bd143e2bb185466cc23.tar.gz rails-ae297710dd526a95bae99bd143e2bb185466cc23.tar.bz2 rails-ae297710dd526a95bae99bd143e2bb185466cc23.zip |
Merge pull request #12011 from jetthoughts/11963_fix_join_with_association_scope
Collapse where constraints to the Arel::Nodes::And node
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/inner_join_association_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/author.rb | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb index de47a576c6..9fe5ff50d9 100644 --- a/activerecord/test/cases/associations/inner_join_association_test.rb +++ b/activerecord/test/cases/associations/inner_join_association_test.rb @@ -41,6 +41,11 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase assert_no_match(/WHERE/i, sql) end + def test_join_association_conditions_support_string_and_arel_expressions + assert_equal 0, Author.joins(:welcome_posts_with_comment).count + assert_equal 1, Author.joins(:welcome_posts_with_comments).count + end + def test_join_conditions_allow_nil_associations authors = Author.includes(:essays).where(:essays => {:id => nil}) assert_equal 2, authors.count diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 7dad8041f3..794d1af43d 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -29,6 +29,13 @@ class Author < ActiveRecord::Base has_many :thinking_posts, -> { where(:title => 'So I was thinking') }, :dependent => :delete_all, :class_name => 'Post' has_many :welcome_posts, -> { where(:title => 'Welcome to the weblog') }, :class_name => 'Post' + has_many :welcome_posts_with_comment, + -> { where(title: 'Welcome to the weblog').where('comments_count = ?', 1) }, + class_name: 'Post' + has_many :welcome_posts_with_comments, + -> { where(title: 'Welcome to the weblog').where(Post.arel_table[:comments_count].gt(0)) }, + class_name: 'Post' + has_many :comments_desc, -> { order('comments.id DESC') }, :through => :posts, :source => :comments has_many :funky_comments, :through => :posts, :source => :comments has_many :ordered_uniq_comments, -> { distinct.order('comments.id') }, :through => :posts, :source => :comments |