diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-11 11:34:18 +0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-11 13:18:20 +0800 |
commit | 5daafa8e959acc64fc19e9522470282ac0f25f33 (patch) | |
tree | 7ca526824f312ac79ca71e491d9df7ea86b5aca7 /lib/arel | |
parent | 8ce904933db3ec9884194f07881581ec0cc8281e (diff) | |
download | rails-5daafa8e959acc64fc19e9522470282ac0f25f33.tar.gz rails-5daafa8e959acc64fc19e9522470282ac0f25f33.tar.bz2 rails-5daafa8e959acc64fc19e9522470282ac0f25f33.zip |
Add Min node.
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/attributes/attribute.rb | 4 | ||||
-rw-r--r-- | lib/arel/nodes.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/min.rb | 6 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 5 |
4 files changed, 16 insertions, 0 deletions
diff --git a/lib/arel/attributes/attribute.rb b/lib/arel/attributes/attribute.rb index 617112f681..34c1f45ba6 100644 --- a/lib/arel/attributes/attribute.rb +++ b/lib/arel/attributes/attribute.rb @@ -25,6 +25,10 @@ module Arel Nodes::Max.new [self], Nodes::SqlLiteral.new('max_id') end + def minimum + Nodes::Min.new [self], Nodes::SqlLiteral.new('min_id') + end + def average Nodes::Avg.new [self], Nodes::SqlLiteral.new('avg_id') end diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 7510214cdf..3ffc81d7df 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -15,6 +15,7 @@ require 'arel/nodes/values' require 'arel/nodes/offset' require 'arel/nodes/sum' require 'arel/nodes/max' +require 'arel/nodes/min' require 'arel/nodes/avg' require 'arel/nodes/having' require 'arel/nodes/sql_literal' diff --git a/lib/arel/nodes/min.rb b/lib/arel/nodes/min.rb new file mode 100644 index 0000000000..bdc1371858 --- /dev/null +++ b/lib/arel/nodes/min.rb @@ -0,0 +1,6 @@ +module Arel + module Nodes + class Min < Arel::Nodes::Function + end + end +end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 599a25836a..65dc5fdb83 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -100,6 +100,11 @@ module Arel visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}" end + def visit_Arel_Nodes_Min o + "MIN(#{o.expressions.map { |x| + visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}" + end + def visit_Arel_Nodes_Avg o "AVG(#{o.expressions.map { |x| visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}" |