aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSzymon Nowak <szimek@gmail.com>2009-08-13 21:18:43 +0200
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-23 15:19:17 -0800
commit85683f2a79dbf81130361cb6426786cf6b0d1925 (patch)
treec802a675983c3a7cb9d3a31ae8adf63d1baca0ca /activerecord/lib
parentb79823832e6cd30a9f14f97ffdf1642d4d63d4ea (diff)
downloadrails-85683f2a79dbf81130361cb6426786cf6b0d1925.tar.gz
rails-85683f2a79dbf81130361cb6426786cf6b0d1925.tar.bz2
rails-85683f2a79dbf81130361cb6426786cf6b0d1925.zip
Fix creation of has_many through records with custom primary_key option on belongs_to [#2990 state:resolved]
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/through_association_scope.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb
index 5dc5b0c048..99920d4c63 100644
--- a/activerecord/lib/active_record/associations/through_association_scope.rb
+++ b/activerecord/lib/active_record/associations/through_association_scope.rb
@@ -106,7 +106,12 @@ module ActiveRecord
# TODO: revisit this to allow it for deletion, supposing dependent option is supported
raise ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection.new(@owner, @reflection) if [:has_one, :has_many].include?(@reflection.source_reflection.macro)
- join_attributes = construct_owner_attributes(@reflection.through_reflection).merge(@reflection.source_reflection.primary_key_name => associate.id)
+ join_attributes = construct_owner_attributes(@reflection.through_reflection)
+
+ join_attributes.merge!(
+ @reflection.source_reflection.primary_key_name =>
+ associate.send(@reflection.source_reflection.association_primary_key)
+ )
if @reflection.options[:source_type]
join_attributes.merge!(@reflection.source_reflection.options[:foreign_type] => associate.class.base_class.name)