diff options
Diffstat (limited to 'lib/arel/engines')
-rw-r--r-- | lib/arel/engines/sql/christener.rb | 13 | ||||
-rw-r--r-- | lib/arel/engines/sql/formatters.rb | 5 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/arel/engines/sql/christener.rb b/lib/arel/engines/sql/christener.rb index a2a2da799a..2c96020554 100644 --- a/lib/arel/engines/sql/christener.rb +++ b/lib/arel/engines/sql/christener.rb @@ -1,13 +1,18 @@ module Arel module Sql class Christener - def name_for(relation) - @used_names ||= Hash.new(0) - (@relation_names ||= Hash.new do |hash, relation| + def initialize + # FIXME: this exists because all objects hash the same. :'( + @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 + end + + def name_for(relation) + @relation_names[relation.table] end end end diff --git a/lib/arel/engines/sql/formatters.rb b/lib/arel/engines/sql/formatters.rb index cdbda5ea33..de8278479d 100644 --- a/lib/arel/engines/sql/formatters.rb +++ b/lib/arel/engines/sql/formatters.rb @@ -1,13 +1,14 @@ module Arel module Sql class Formatter - attr_reader :environment - delegate :christener, :engine, :to => :environment + attr_reader :environment, :christener + delegate :engine, :to => :environment delegate :name_for, :to => :christener delegate :quote_table_name, :quote_column_name, :quote, :to => :engine def initialize(environment) @environment = environment + @christener = environment.christener end end |