aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-14 07:19:47 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-14 07:19:47 +0000
commitd7f780e0664ebb939ce76d987cd30c6eec496dc7 (patch)
treeb042533b274e034805ff94fd0e6f9d50713f3592 /activerecord/lib/active_record/associations.rb
parent8c4b599b7c62b85069fa04533e8f06e5476f927a (diff)
downloadrails-d7f780e0664ebb939ce76d987cd30c6eec496dc7.tar.gz
rails-d7f780e0664ebb939ce76d987cd30c6eec496dc7.tar.bz2
rails-d7f780e0664ebb939ce76d987cd30c6eec496dc7.zip
Fix for deep includes on the same association.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4758 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb11
1 files changed, 9 insertions, 2 deletions
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