aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb3
-rw-r--r--activerecord/test/cases/relations_test.rb5
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 03f194c462..9e855209f9 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -24,7 +24,8 @@ module ActiveRecord
case value
when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope
- attribute.in(value.to_a)
+ values = value.to_a
+ values.any? ? attribute.in(values) : attribute.eq(nil)
when Range
# TODO : Arel should handle ranges with excluded end.
if value.exclude_end?
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index e31d0ee3e8..d34c9b4895 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -339,6 +339,11 @@ class RelationTest < ActiveRecord::TestCase
assert_raises(ActiveRecord::RecordNotFound) { authors.find(['42', 43]) }
end
+ def test_find_in_empty_array
+ authors = Author.scoped.where(:id => [])
+ assert authors.all.blank?
+ end
+
def test_exists
davids = Author.where(:name => 'David')
assert davids.exists?