diff options
author | Szymon Nowak <szimek@gmail.com> | 2009-08-13 21:18:43 +0200 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-23 15:19:17 -0800 |
commit | 85683f2a79dbf81130361cb6426786cf6b0d1925 (patch) | |
tree | c802a675983c3a7cb9d3a31ae8adf63d1baca0ca /activerecord/lib/active_record | |
parent | b79823832e6cd30a9f14f97ffdf1642d4d63d4ea (diff) | |
download | rails-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/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association_scope.rb | 7 |
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) |