Permalink
Browse files

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

  • Loading branch information...
rywall committed Sep 6, 2013
1 parent 6a91a33 commit 87a84d3263c8712f85e70c45803203fa54658a9e
@@ -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)

0 comments on commit 87a84d3

Please sign in to comment.