diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-08-11 17:58:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 17:58:02 -0400 |
commit | 5834d2f5d98af4469db2f7f68b5a4ecb98db87b6 (patch) | |
tree | a85860f19c5e001a583e3d7295416c4a3fb38e05 /activerecord/test/cases | |
parent | b9e0b4f19940fdd7105db3dffc507cbd89ac3705 (diff) | |
parent | 5f64f361aea5a59c5782ed9d635668a738d9fabd (diff) | |
download | rails-5834d2f5d98af4469db2f7f68b5a4ecb98db87b6.tar.gz rails-5834d2f5d98af4469db2f7f68b5a4ecb98db87b6.tar.bz2 rails-5834d2f5d98af4469db2f7f68b5a4ecb98db87b6.zip |
Merge pull request #30126 from chopraanmol1/support_for_has_many_and_has_one_for_where_relation
Fixed query building when relation is passed for has one or has many association in where
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relation/where_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index c45fd38bc9..2fe2a67b1c 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -295,6 +295,20 @@ module ActiveRecord assert_equal essays(:david_modest_proposal), essay end + def test_where_with_relation_on_has_many_association + essay = essays(:david_modest_proposal) + author = Author.where(essays: Essay.where(id: essay.id)).first + + assert_equal authors(:david), author + end + + def test_where_with_relation_on_has_one_association + author = authors(:david) + author_address = AuthorAddress.where(author: Author.where(id: author.id)).first + assert_equal author_addresses(:david_address), author_address + end + + def test_where_on_association_with_select_relation essay = Essay.where(author: Author.where(name: "David").select(:name)).take assert_equal essays(:david_modest_proposal), essay |