From fe67dfbbeea092f0f42e81e4901fe9a949cf9484 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Thu, 14 Aug 2014 13:44:29 +0300 Subject: Fixed AR::Relation#where edge case with Hash and other Relation Example: Author.where(posts: { author_id: Author.where(country_id: 1) }).joins(:posts) --- activerecord/test/cases/relation/where_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test/cases/relation/where_test.rb') diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index a6a36a6fd9..b4804aa9d7 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -61,6 +61,15 @@ module ActiveRecord assert_equal expected.to_sql, actual.to_sql end + def test_belongs_to_nested_where_with_relation + author = authors(:david) + + expected = Author.where(id: author ).joins(:posts) + actual = Author.where(posts: { author_id: Author.where(id: author.id) }).joins(:posts) + + assert_equal expected.to_a, actual.to_a + end + def test_polymorphic_shallow_where treasure = Treasure.new treasure.id = 1 -- cgit v1.2.3