From 8d270a2abbc1601777f4918bd1968c18f7864ae5 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Thu, 5 May 2011 12:35:29 -0400 Subject: Add join conditions to JOIN clause, not WHERE --- activerecord/test/cases/associations/inner_join_association_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb index e2228228a3..cc19c874f0 100644 --- a/activerecord/test/cases/associations/inner_join_association_test.rb +++ b/activerecord/test/cases/associations/inner_join_association_test.rb @@ -34,6 +34,12 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase assert_no_match(/JOIN/i, sql) end + def test_join_conditions_added_to_join_clause + sql = Author.joins(:essays).to_sql + assert_match(/writer_type.*?=.*?Author/i, sql) + assert_no_match(/WHERE/i, sql) + end + def test_find_with_implicit_inner_joins_honors_readonly_without_select authors = Author.joins(:posts).to_a assert !authors.empty?, "expected authors to be non-empty" -- cgit v1.2.3 From 9b7cd75db340b6d0c6f2ec342ae4d7a201e46e84 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Thu, 5 May 2011 14:34:48 -0400 Subject: Add a test for outer joins with conditions where value IS NULL --- activerecord/test/cases/associations/inner_join_association_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb index cc19c874f0..124693f7c9 100644 --- a/activerecord/test/cases/associations/inner_join_association_test.rb +++ b/activerecord/test/cases/associations/inner_join_association_test.rb @@ -40,6 +40,11 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase assert_no_match(/WHERE/i, sql) end + def test_join_conditions_allow_nil_associations + authors = Author.includes(:essays).where(:essays => {:id => nil}) + assert_equal 2, authors.count + end + def test_find_with_implicit_inner_joins_honors_readonly_without_select authors = Author.joins(:posts).to_a assert !authors.empty?, "expected authors to be non-empty" -- cgit v1.2.3