mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow Relation#from to accept other relations with bind values.
This commit is contained in:
parent
6a91a3307f
commit
87a84d3263
3 changed files with 12 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
* Allow Relation#from to accept other relations with bind values.
|
||||
|
||||
*Ryan Wallace*
|
||||
|
||||
* Re-use `order` argument pre-processing for `reorder`.
|
||||
|
||||
*Paul Nikitochkin*
|
||||
|
|
|
@ -915,6 +915,7 @@ module ActiveRecord
|
|||
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 @@ class RelationTest < ActiveRecord::TestCase
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue