aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-13 19:44:43 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-13 19:44:43 -0300
commit9ea4d4689711d86777715360da47ae25c0acc337 (patch)
treeb518b650e47d1b69f1b7aaa571a81506a1c6e908
parent282bb10a6dcd7e488ea441dd40033bf0f9ecb6c3 (diff)
parent99d6646e8ad9499ee54c703d21e6c9c5fb233965 (diff)
downloadrails-9ea4d4689711d86777715360da47ae25c0acc337.tar.gz
rails-9ea4d4689711d86777715360da47ae25c0acc337.tar.bz2
rails-9ea4d4689711d86777715360da47ae25c0acc337.zip
Merge pull request #290 from mekishizufu/fix_select_manager_as_subquery
Support passing of SelectManager to attribute methods
-rw-r--r--lib/arel/nodes.rb2
-rw-r--r--test/attributes/test_attribute.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index a68e327983..c6bde8c3cc 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -78,7 +78,7 @@ module Arel
def self.build_quoted other, attribute = nil
case other
- when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Nodes::SelectStatement, Arel::Table, Arel::Nodes::BindParam
+ when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager
other
else
case attribute
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb
index 145da98968..38ee189a46 100644
--- a/test/attributes/test_attribute.rb
+++ b/test/attributes/test_attribute.rb
@@ -74,6 +74,17 @@ module Arel
SELECT "users"."id" FROM "users" WHERE "users"."id" > 10
}
end
+
+ it 'should handle comparing with a subquery' do
+ users = Table.new(:users)
+
+ avg = users.project(users[:karma].average)
+ mgr = users.project(Arel.star).where(users[:karma].gt(avg))
+
+ mgr.to_sql.must_be_like %{
+ SELECT * FROM "users" WHERE "users"."karma" > (SELECT AVG("users"."karma") AS avg_id FROM "users")
+ }
+ end
end
describe '#gt_any' do