Class: RecordFilter::GroupBy

Inherits:
Object
  • Object
show all
Defined in:
lib/record_filter/group_by.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column, table) ⇒ GroupBy

Returns a new instance of GroupBy.



5
6
7
# File 'lib/record_filter/group_by.rb', line 5

def initialize(column, table)
  @column, @table = column, table
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



3
4
5
# File 'lib/record_filter/group_by.rb', line 3

def column
  @column
end

#tableObject (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/record_filter/group_by.rb', line 3

def table
  @table
end

Instance Method Details

#to_sqlObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/record_filter/group_by.rb', line 9

def to_sql
  table, column = @table, @column
  while column.is_a?(Hash)
    table = table.join_association(column.keys[0]).right_table
    column = column.values[0]
  end

  if (!table.has_column(column))
    raise ColumnNotFoundException.new("The column #{column} was not found in #{table.table_name}.")
  end

  "#{table.table_alias}.#{column}"
end