1
0
Fork 0
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:
Ryan Wallace 2013-09-06 15:16:39 -07:00
parent 6a91a3307f
commit 87a84d3263
3 changed files with 12 additions and 0 deletions

View file

@ -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*

View file

@ -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

View file

@ -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)