Class: Arel::Sql::Christener

Inherits:
Object
  • Object
show all
Defined in:
lib/arel/engines/sql/christener.rb

Instance Method Summary collapse

Constructor Details

#initializeChristener

Returns a new instance of Christener.



4
5
6
# File 'lib/arel/engines/sql/christener.rb', line 4

def initialize
  @names = {}
end

Instance Method Details

#name_for(relation) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/arel/engines/sql/christener.rb', line 8

def name_for(relation)
  table = relation.table
  name = table.table_alias || table.name
  list = @names[name] ||= []

  list << table unless list.include? table

  idx = list.index table
  name + (idx == 0 ? '' : "_#{idx + 1}")
end