Class: Arel::Sql::Christener

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

Instance Method Summary collapse

Instance Method Details

#name_for(relation) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/arel/engines/sql/christener.rb', line 4

def name_for(relation)
  @used_names ||= Hash.new(0)
  (@relation_names ||= Hash.new do |hash, relation|
    name =  relation.table_alias ? relation.table_alias : relation.name
    @used_names[name] += 1
    hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '')
  end)[relation.table]
end