Permalink
Browse files

slight change to eager associations table aliasing: use class_reflect…

…ion, like 'post_comments' or 'tree_children'

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3788 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5a7722d commit c58dff1c9cbdd45df8685e230d1dc91cf1deb6cf @technoweenie technoweenie committed Mar 6, 2006
Showing with 3 additions and 3 deletions.
  1. +2 −2 activerecord/CHANGELOG
  2. +1 −1 activerecord/lib/active_record/associations.rb
View
@@ -3,9 +3,9 @@
* Added smarter table aliasing for eager associations for multiple self joins #3580 [Rick Olson]
* The first time a table is referenced in a join, no alias is used.
- * After that, the parent table name and the reflection name are used.
+ * After that, the parent class name and the reflection name are used.
- Tree.find(:all, :include => :children) # LEFT OUTER JOIN trees AS tress_children ...
+ Tree.find(:all, :include => :children) # LEFT OUTER JOIN trees AS tree_children ...
* Any additional join references get a numerical suffix like '_2', '_3', etc.
@@ -1197,7 +1197,7 @@ def initialize(reflection, join_dependency, parent = nil)
unless join_dependency.table_aliases[aliased_table_name].zero?
# if the table name has been used, then use an alias
# if the alias has been used, add a '_n' suffix to the end.
- @aliased_table_name = "#{parent.table_name}_#{reflection.name}_#{join_dependency.table_aliases[aliased_table_name]}".gsub(/_1$/, '')
+ @aliased_table_name = "#{parent.active_record.to_s.underscore}_#{reflection.name}_#{join_dependency.table_aliases[aliased_table_name]}".gsub(/_1$/, '')
end
join_dependency.table_aliases[aliased_table_name] += 1
end

0 comments on commit c58dff1

Please sign in to comment.