提交 4aa89eda 编写于 作者: R Rafael Mendonça França

Merge pull request #12156 from rywall/from-copy-binds

Allow Relation#from to accept other relations with bind values.

Conflicts:
	activerecord/CHANGELOG.md
* Allow Relation#from to accept other relations with bind values.
*Ryan Wallace*
* Fix inserts with prepared statements disabled.
Fixes #12023.
......
......@@ -915,6 +915,7 @@ def build_from
case opts
when Relation
name ||= 'subquery'
self.bind_values = opts.bind_values + self.bind_values
opts.arel.as(name.to_s)
else
opts
......
......@@ -139,6 +139,13 @@ def test_finding_with_subquery
assert_equal relation.to_a, Topic.select('a.*').from(relation, :a).to_a
end
def test_finding_with_subquery_with_binds
relation = Post.first.comments
assert_equal relation.to_a, Comment.select('*').from(relation).to_a
assert_equal relation.to_a, Comment.select('subquery.*').from(relation).to_a
assert_equal relation.to_a, Comment.select('a.*').from(relation, :a).to_a
end
def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册