aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-05 17:01:56 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-05 17:01:56 +0000
commita9fb1544b0e7e6412e4cb64702585024e24276bf (patch)
tree6f9b5c099d3304184c284aa0219add424be6e2b6 /activerecord/lib
parent4d232025b7260834dc4a4403b2b9effd043215c4 (diff)
downloadrails-a9fb1544b0e7e6412e4cb64702585024e24276bf.tar.gz
rails-a9fb1544b0e7e6412e4cb64702585024e24276bf.tar.bz2
rails-a9fb1544b0e7e6412e4cb64702585024e24276bf.zip
Added support for eagerly including polymorphic has_one associations. (closes #4525) [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4170 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 5319fa39e8..7b6257ec03 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1392,7 +1392,7 @@ module ActiveRecord
@aliased_prefix = "t#{ join_dependency.joins.size }"
@aliased_table_name = table_name # start with the table name
@parent_table_name = parent.active_record.table_name
-
+
if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{aliased_table_name.downcase}\son}
join_dependency.table_aliases[aliased_table_name] += 1
end
@@ -1473,12 +1473,16 @@ module ActiveRecord
aliased_table_name, "#{reflection.options[:as]}_type",
klass.quote(parent.active_record.base_class.name)
]
-
+ when reflection.macro == :has_one && reflection.options[:as]
+ " LEFT OUTER JOIN %s ON %s.%s = %s.%s AND %s.%s = %s " % [
+ table_name_and_alias,
+ aliased_table_name, "#{reflection.options[:as]}_id",
+ parent.aliased_table_name, parent.primary_key,
+ aliased_table_name, "#{reflection.options[:as]}_type",
+ klass.quote(reflection.active_record.name)
+ ]
else
- foreign_key = options[:foreign_key] || case reflection.macro
- when :has_many then reflection.active_record.to_s.classify
- when :has_one then reflection.active_record.to_s
- end.foreign_key
+ foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
" LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [
table_name_and_alias,
aliased_table_name, foreign_key,