1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix select_all with legacy binds

Fixes #27923.
This commit is contained in:
Ryuta Kamizono 2017-02-08 08:52:21 +09:00
parent 4172c810af
commit 2f8cef92bb
2 changed files with 14 additions and 1 deletions

View file

@ -158,7 +158,11 @@ module ActiveRecord
private private
def type_casted_binds(binds) def type_casted_binds(binds)
binds.map { |attr| type_cast(attr.value_for_database) } if binds.first.is_a?(Array)
binds.map { |column, value| type_cast(value, column) }
else
binds.map { |attr| type_cast(attr.value_for_database) }
end
end end
def types_which_need_no_typecasting def types_which_need_no_typecasting

View file

@ -244,6 +244,15 @@ module ActiveRecord
assert result.is_a?(ActiveRecord::Result) assert result.is_a?(ActiveRecord::Result)
end end
if ActiveRecord::Base.connection.prepared_statements
def test_select_all_with_legacy_binds
post = Post.create!(title: "foo", body: "bar")
expected = @connection.select_all("SELECT * FROM posts WHERE id = #{post.id}")
result = @connection.select_all("SELECT * FROM posts WHERE id = #{Arel::Nodes::BindParam.new.to_sql}", nil, [[nil, post.id]])
assert_equal expected.to_hash, result.to_hash
end
end
def test_select_methods_passing_a_association_relation def test_select_methods_passing_a_association_relation
author = Author.create!(name: 'john') author = Author.create!(name: 'john')
Post.create!(author: author, title: 'foo', body: 'bar') Post.create!(author: author, title: 'foo', body: 'bar')