Class: ActiveRecord::Refined::AST::GroupingSets
- Defined in:
- lib/active_record/refined/ast.rb
Overview
GROUP BY GROUPING SETS / ROLLUP / CUBE: several groupings asked for at once, the totals of each coming back beside the rows. PostgreSQL has all three; the block raises for the others before it gets this far.
Each set is a list of its own, so grouping_sets takes lists and rollup and cube take the columns themselves.
Constant Summary collapse
- KINDS =
{ grouping_sets: Arel::Nodes::GroupingSet, rollup: Arel::Nodes::RollUp, cube: Arel::Nodes::Cube, }.freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#sets ⇒ Object
readonly
Returns the value of attribute sets.
Instance Method Summary collapse
-
#initialize(kind, sets) ⇒ GroupingSets
constructor
A new instance of GroupingSets.
- #to_arel(table, model) ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(kind, sets) ⇒ GroupingSets
Returns a new instance of GroupingSets.
660 661 662 663 664 |
# File 'lib/active_record/refined/ast.rb', line 660 def initialize(kind, sets) raise ArgumentError, "#{kind} needs something to group by" if sets.empty? @kind = kind @sets = sets end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
658 659 660 |
# File 'lib/active_record/refined/ast.rb', line 658 def kind @kind end |
#sets ⇒ Object (readonly)
Returns the value of attribute sets.
658 659 660 |
# File 'lib/active_record/refined/ast.rb', line 658 def sets @sets end |
Instance Method Details
#to_arel(table, model) ⇒ Object
666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/active_record/refined/ast.rb', line 666 def to_arel(table, model) KINDS.fetch(kind).new( if kind == :grouping_sets sets.map do |set| Arel::Nodes::GroupingElement.new( Array(set).map {|column| to_arel_operand(column, table, model) }) end else sets.map {|column| to_arel_operand(column, table, model) } end) end |