Allow Relation#from to accept other relations with bind values.
This commit is contained in:
parent
6a91a3307f
commit
87a84d3263
@ -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 @@ 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)
|
||||
|
Loading…
Reference in New Issue
Block a user