Class: ActiveRecord::Calculations::ColumnAliasTracker
- Inherits:
-
Object
- Object
- ActiveRecord::Calculations::ColumnAliasTracker
- Defined in:
- lib/active_record/relation/calculations.rb
Overview
:nodoc:
Instance Method Summary collapse
- #alias_for(field) ⇒ Object
-
#initialize(connection) ⇒ ColumnAliasTracker
constructor
A new instance of ColumnAliasTracker.
Constructor Details
#initialize(connection) ⇒ ColumnAliasTracker
Returns a new instance of ColumnAliasTracker.
9 10 11 12 |
# File 'lib/active_record/relation/calculations.rb', line 9 def initialize(connection) @connection = connection @aliases = Hash.new(0) end |
Instance Method Details
#alias_for(field) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_record/relation/calculations.rb', line 14 def alias_for(field) aliased_name = column_alias_for(field) if @aliases[aliased_name] == 0 @aliases[aliased_name] = 1 aliased_name else # Update the count count = @aliases[aliased_name] += 1 "#{truncate(aliased_name)}_#{count}" end end |