提交 d4c3db0d 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #27939 from kamipo/fix_select_all_with_legacy_binds

Fix `select_all` with legacy `binds`
......@@ -155,7 +155,11 @@ def quoted_binary(value) # :nodoc:
private
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
def id_value_for_database(value)
......
......@@ -216,6 +216,15 @@ def test_select_all_always_return_activerecord_result
assert result.is_a?(ActiveRecord::Result)
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
author = Author.create!(name: "john")
Post.create!(author: author, title: "foo", body: "bar")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册