diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-20 14:00:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-20 14:00:06 -0700 |
commit | 2567b72f9582c14a591156653e2b656d48200b11 (patch) | |
tree | 3f0b89b8ccc8ccc37f5233ca628d550b3cc6ec9a /lib/arel | |
parent | 7832cd3bb3c6cfd76fdb63ca75995f2e6c87757c (diff) | |
download | rails-2567b72f9582c14a591156653e2b656d48200b11.tar.gz rails-2567b72f9582c14a591156653e2b656d48200b11.tar.bz2 rails-2567b72f9582c14a591156653e2b656d48200b11.zip |
supressing nested parenthesis in multiple unions on mysql. thanks jhtwong. fixes #58
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/visitors/mysql.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb index 763cf11aad..70166a15c5 100644 --- a/lib/arel/visitors/mysql.rb +++ b/lib/arel/visitors/mysql.rb @@ -2,6 +2,28 @@ module Arel module Visitors class MySQL < Arel::Visitors::ToSql private + def visit_Arel_Nodes_Union o, suppress_parens = false + left_result = case o.left + when Arel::Nodes::Union + visit_Arel_Nodes_Union o.left, true + else + visit o.left + end + + right_result = case o.right + when Arel::Nodes::Union + visit_Arel_Nodes_Union o.right, true + else + visit o.right + end + + if suppress_parens + "#{left_result} UNION #{right_result}" + else + "( #{left_result} UNION #{right_result} )" + end + end + def visit_Arel_Nodes_Bin o "BINARY #{visit o.expr}" end |