aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/sql/christener.rb
blob: c1c9325208b19da2aeb02b73c4646586d4c4e074 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
module Arel
  module Sql
    class Christener
      def name_for(relation)
        @used_names ||= Hash.new(0)
        (@relation_names ||= Hash.new do |hash, relation|
          @used_names[name = relation.name] += 1
          hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '')
        end)[relation.table]
      end
    end
  end
end