diff options
author | vijay <vijaydev.cse@gmail.com> | 2010-12-10 23:03:31 +0530 |
---|---|---|
committer | vijay <vijaydev.cse@gmail.com> | 2010-12-10 23:03:31 +0530 |
commit | 6acd1304b15de65e1ab38437357ce63b80f4e7c0 (patch) | |
tree | c3dc8d8701a07f3156f8d02d6f2606b23aea159a /activerecord/lib/active_record/associations/class_methods/join_dependency | |
parent | 638b409eb4c75b9187c6cedc9f71e2e38ec84731 (diff) | |
parent | dbf955c03b8d185b7977d90281389cf52d546c5d (diff) | |
download | rails-6acd1304b15de65e1ab38437357ce63b80f4e7c0.tar.gz rails-6acd1304b15de65e1ab38437357ce63b80f4e7c0.tar.bz2 rails-6acd1304b15de65e1ab38437357ce63b80f4e7c0.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activerecord/lib/active_record/associations/class_methods/join_dependency')
2 files changed, 11 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb index 4dd11a7366..25511a092f 100644 --- a/activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb @@ -67,8 +67,7 @@ module ActiveRecord def table @table ||= Arel::Table.new( - table_name, :as => aliased_table_name, - :engine => arel_engine, :columns => active_record.columns + table_name, :as => aliased_table_name, :engine => arel_engine ) end @@ -78,23 +77,18 @@ module ActiveRecord protected def aliased_table_name_for(name, suffix = nil) - if @join_dependency.table_aliases[name].zero? - @join_dependency.table_aliases[name] = @join_dependency.count_aliases_from_table_joins(name) - end + aliases = @join_dependency.table_aliases - if !@join_dependency.table_aliases[name].zero? # We need an alias - name = active_record.connection.table_alias_for "#{pluralize(reflection.name)}_#{parent_table_name}#{suffix}" - @join_dependency.table_aliases[name] += 1 - if @join_dependency.table_aliases[name] == 1 # First time we've seen this name - # Also need to count the aliases from the table_aliases to avoid incorrect count - @join_dependency.table_aliases[name] += @join_dependency.count_aliases_from_table_joins(name) - end - table_index = @join_dependency.table_aliases[name] - name = name[0..active_record.connection.table_alias_length-3] + "_#{table_index}" if table_index > 1 - else - @join_dependency.table_aliases[name] += 1 + if aliases[name] != 0 # We need an alias + connection = active_record.connection + + name = connection.table_alias_for "#{pluralize(reflection.name)}_#{parent_table_name}#{suffix}" + table_index = aliases[name] + 1 + name = name[0, connection.table_alias_length-3] + "_#{table_index}" if table_index > 1 end + aliases[name] += 1 + name end diff --git a/activerecord/lib/active_record/associations/class_methods/join_dependency/join_base.rb b/activerecord/lib/active_record/associations/class_methods/join_dependency/join_base.rb index 97003c1457..67567f06df 100644 --- a/activerecord/lib/active_record/associations/class_methods/join_dependency/join_base.rb +++ b/activerecord/lib/active_record/associations/class_methods/join_dependency/join_base.rb @@ -13,7 +13,7 @@ module ActiveRecord end def table - Arel::Table.new(table_name, :engine => arel_engine, :columns => active_record.columns) + Arel::Table.new(table_name, arel_engine) end def aliased_table_name |