diff --git a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb index 4b5f5773a0d010f3059dabec71334c23fe889139..7c90563d96d64efc29a3c7a6c15d6057ea65e647 100644 --- a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb +++ b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb @@ -19,7 +19,12 @@ def call(attribute, value) case values.length when 0 then NullPredicate when 1 then predicate_builder.build(attribute, values.first) - else attribute.in(values) + else + attribute_name = attribute.name + casted_values = values.map do |v| + predicate_builder.type_cast_for_database(attribute_name, v) + end + attribute.in(casted_values) end unless nils.empty? diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index 3a02e8230d44ddbc3644b6a574fbddf11d220f18..f9d3badcebbb2cefce4ca231455352824a506861 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -36,7 +36,8 @@ def test_not_with_nil end def test_not_in - expected = Post.arel_table[@name].not_in(%w[hello goodbye]) + values = %w[hello goodbye].map { |v| Arel::Nodes::Quoted.new(v) } + expected = Post.arel_table[@name].not_in(values) relation = Post.where.not(title: %w[hello goodbye]) assert_equal([expected], relation.where_values) end @@ -90,7 +91,10 @@ def test_not_eq_with_array_parameter def test_chaining_multiple relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails') - expected = Post.arel_table['author_id'].not_in([1, 2]) + expected = Post.arel_table['author_id'].not_in([ + Arel::Nodes::Quoted.new(1), + Arel::Nodes::Quoted.new(2), + ]) assert_equal(expected, relation.where_values[0]) value = relation.where_values[1]