From d7f780e0664ebb939ce76d987cd30c6eec496dc7 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Aug 2006 07:19:47 +0000 Subject: Fix for deep includes on the same association. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4758 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index c803560413..4f2d8a7999 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1393,11 +1393,13 @@ module ActiveRecord unless join_dependency.table_aliases[aliased_table_name].zero? # if the table name has been used, then use an alias - @aliased_table_name = active_record.connection.table_alias_for "#{pluralize(reflection.name)}_#{parent_table_name}" + @aliased_table_name = cascade_alias table_index = join_dependency.table_aliases[aliased_table_name] + join_dependency.table_aliases[@aliased_table_name] += 1 @aliased_table_name = @aliased_table_name[0..active_record.connection.table_alias_length-3] + "_#{table_index+1}" if table_index > 0 + else + join_dependency.table_aliases[aliased_table_name] += 1 end - join_dependency.table_aliases[aliased_table_name] += 1 if reflection.macro == :has_and_belongs_to_many || (reflection.macro == :has_many && reflection.options[:through]) @aliased_join_table_name = reflection.macro == :has_and_belongs_to_many ? reflection.options[:join_table] : reflection.through_reflection.klass.table_name @@ -1529,6 +1531,11 @@ module ActiveRecord def interpolate_sql(sql) instance_eval("%@#{sql.gsub('@', '\@')}@") end + + private + def cascade_alias + active_record.connection.table_alias_for "#{pluralize(reflection.name)}_#{parent_table_name}" + end end end end -- cgit v1.2.3