aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2010-03-29 16:38:44 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2010-03-29 15:24:27 -0700
commit63026541b209cc11ffd74cf3ca04b89d1e437737 (patch)
tree6f274f2d13577e64f03160fc788b705c9893f85e /activerecord/lib
parenta509b0b18fd02d1d712248ce94e1d36750d58565 (diff)
downloadrails-63026541b209cc11ffd74cf3ca04b89d1e437737.tar.gz
rails-63026541b209cc11ffd74cf3ca04b89d1e437737.tar.bz2
rails-63026541b209cc11ffd74cf3ca04b89d1e437737.zip
Fix honoring :primary_key option when joining or eager loading a belongs_to association
[#765 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/association_preload.rb2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb2
2 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 6725d4e88b..c94b2ff564 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -324,7 +324,7 @@ module ActiveRecord
klass = klass_name.constantize
table_name = klass.quoted_table_name
- primary_key = klass.primary_key
+ primary_key = reflection.options[:primary_key] || klass.primary_key
column_type = klass.columns.detect{|c| c.name == primary_key}.type
ids = id_map.keys.map do |id|
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index ee87cb9b41..7406daf837 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -2031,7 +2031,7 @@ module ActiveRecord
[aliased_table[foreign_key].eq(parent_table[reflection.options[:primary_key] || parent.primary_key])]
end
when :belongs_to
- [aliased_table[reflection.klass.primary_key].eq(parent_table[options[:foreign_key] || reflection.primary_key_name])]
+ [aliased_table[options[:primary_key] || reflection.klass.primary_key].eq(parent_table[options[:foreign_key] || reflection.primary_key_name])]
end
unless klass.descends_from_active_record?