diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-23 12:04:13 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-23 12:05:14 -0700 |
commit | b9d668f8cb466ab70e107e8ed6e1df2d28c25f31 (patch) | |
tree | c1213b08840355cd4c1390c50e81547018e6746b | |
parent | 2698e187578d29292eef3e1cb54338a3afd45a1f (diff) | |
download | rails-b9d668f8cb466ab70e107e8ed6e1df2d28c25f31.tar.gz rails-b9d668f8cb466ab70e107e8ed6e1df2d28c25f31.tar.bz2 rails-b9d668f8cb466ab70e107e8ed6e1df2d28c25f31.zip |
Don't remove join dependencies in `Relation#exists?`
Fixes #18632
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 6 |
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index cb3e27838b..63cd715920 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,9 @@ +* Don't remove join dependencies in `Relation#exists?` + + Fixes #18632 + + *Sean Griffin* + * Invalid values assigned to a JSON column are assumed to be `nil`. Fixes #18629. diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 088bc203b7..c83abfba06 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -307,7 +307,7 @@ module ActiveRecord relation = relation.where(conditions) else unless conditions == :none - relation = where(primary_key => conditions) + relation = relation.where(primary_key => conditions) end end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 9631ea79be..d272b9b929 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -857,6 +857,12 @@ class RelationTest < ActiveRecord::TestCase assert ! fake.exists?(authors(:david).id) end + def test_exists_uses_existing_scope + post = authors(:david).posts.first + authors = Author.includes(:posts).where(name: "David", posts: { id: post.id }) + assert authors.exists?(authors(:david).id) + end + def test_last authors = Author.all assert_equal authors(:bob), authors.last |