diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-19 19:32:07 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-19 19:32:07 +0000 |
commit | 9a72cd22cf427754a30af409c4651da2017296a8 (patch) | |
tree | 1f616bb17910fdc6a0c530e1bac2ee48db3f6b65 /activerecord/lib/active_record | |
parent | 48e7edc31b873c343d3e696fc02af354a74f0683 (diff) | |
download | rails-9a72cd22cf427754a30af409c4651da2017296a8.tar.gz rails-9a72cd22cf427754a30af409c4651da2017296a8.tar.bz2 rails-9a72cd22cf427754a30af409c4651da2017296a8.zip |
Don't classify the has_one class when eager loading, it is already singular. Add tests. (closes #4117) [jonathan@bluewire.net.nz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3983 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 14a3eeb1eb..6f149d16e0 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1310,28 +1310,27 @@ module ActiveRecord " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [table_name_and_alias, aliased_table_name, primary_key, aliased_join_table_name, options[:foreign_key] || reflection.klass.to_s.classify.foreign_key ] - elsif source_reflection.macro == :belongs_to # has_many :through against a belongs_to - " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [ - table_alias_for(through_reflection.klass.table_name, aliased_join_table_name), aliased_join_table_name, - through_reflection.primary_key_name, - parent.aliased_table_name, parent.primary_key] + - " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [ - table_name_and_alias, - aliased_table_name, primary_key, - aliased_join_table_name, options[:foreign_key] || klass.to_s.classify.foreign_key - ] - elsif source_reflection.macro == :has_many # has_many :through against a has_many + else + case source_reflection.macro + when :belongs_to + first_key = primary_key + second_key = options[:foreign_key] || klass.to_s.classify.foreign_key + when :has_many + first_key = through_reflection.klass.to_s.classify.foreign_key + second_key = options[:foreign_key] || primary_key + end + " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [ table_alias_for(through_reflection.klass.table_name, aliased_join_table_name), aliased_join_table_name, through_reflection.primary_key_name, parent.aliased_table_name, parent.primary_key] + " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [ table_name_and_alias, - aliased_table_name, through_reflection.klass.to_s.classify.foreign_key, - aliased_join_table_name, options[:foreign_key] || primary_key + aliased_table_name, first_key, + aliased_join_table_name, second_key ] end - + when reflection.macro == :has_many && reflection.options[:as] " LEFT OUTER JOIN %s ON %s.%s = %s.%s AND %s.%s = %s" % [ table_name_and_alias, @@ -1342,9 +1341,13 @@ module ActiveRecord ] 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 " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [ table_name_and_alias, - aliased_table_name, options[:foreign_key] || reflection.active_record.to_s.classify.foreign_key, + aliased_table_name, foreign_key, parent.aliased_table_name, parent.primary_key ] end |