diff options
author | chopraanmol1 <chopraanmol1@gmail.com> | 2017-08-08 03:23:45 +0530 |
---|---|---|
committer | chopraanmol1 <chopraanmol1@gmail.com> | 2017-08-08 03:23:45 +0530 |
commit | 7919d5ca7b11107671a72fa0cfd2adc139954e4e (patch) | |
tree | ddeabe7cbc98ed19384f9374e7b35f2b53f04cae /activerecord/test | |
parent | df94b863c2ff8f1bcf12e36ed8fc1419292668e7 (diff) | |
download | rails-7919d5ca7b11107671a72fa0cfd2adc139954e4e.tar.gz rails-7919d5ca7b11107671a72fa0cfd2adc139954e4e.tar.bz2 rails-7919d5ca7b11107671a72fa0cfd2adc139954e4e.zip |
Currently if relation object are passed to where condition for has one or has many association wrong set of primary key and foreign key are selected.
Changed code to use 'join' primary key and foreign key over 'association' primary key and foreign key.
Diffstat (limited to 'activerecord/test')
-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 |