Module: ChronoModel::TimeMachine::HistoryMethods::HistorySelect

Defined in:
lib/chrono_model/time_machine.rb

Overview

:nodoc:

Constant Summary collapse

Aggregates =
%r{(?:(?:bit|bool)_(?:and|or)|(?:array_|string_|xml)agg|count|every|m(?:in|ax)|sum|stddev|var(?:_pop|_samp|iance)|corr|covar_|regr_)\w*\s*\(}i
SELECT_VALUES =
"upper(validity) AS as_of_time"
ORDER_VALUES =
lambda {|tbl| %[#{tbl}."recorded_at", #{tbl}."hid"]}

Instance Method Summary collapse

Instance Method Details

#build_arelObject



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/chrono_model/time_machine.rb', line 535

def build_arel
  has_aggregate = select_values.any? do |v|
    v.kind_of?(Arel::Nodes::Function) || # FIXME this is a bit ugly.
    v.to_s =~ Aggregates
  end

  return super if has_aggregate

  if order_values.blank?
    self.order_values += [ ORDER_VALUES[quoted_table_name] ]
  end

  super.tap do |rel|
    rel.project(SELECT_VALUES)
  end
end