aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_proxy.rb
diff options
context:
space:
mode:
authorRoman Shterenzon <romanbsd@yahoo.com>2008-12-27 01:10:29 +0000
committerYehuda Katz <wycats@gmail.com>2009-01-01 00:13:10 -0800
commit7276128fb47d5997437eb5452b4e9a82ee54f4a8 (patch)
tree4e5057bcecb2312c636da67209a2b25a6ece9ab9 /activerecord/lib/active_record/associations/association_proxy.rb
parent27cfeb7cbcc725c36053833ca8e12cc26357a170 (diff)
downloadrails-7276128fb47d5997437eb5452b4e9a82ee54f4a8.tar.gz
rails-7276128fb47d5997437eb5452b4e9a82ee54f4a8.tar.bz2
rails-7276128fb47d5997437eb5452b4e9a82ee54f4a8.zip
Fix HasManyAssociation#create ignoring the :primary_key option [#1633 state:resolved]
Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/associations/association_proxy.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 59f1d3b867..676c4ace61 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -180,7 +180,10 @@ module ActiveRecord
record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s
else
- record[@reflection.primary_key_name] = @owner.id unless @owner.new_record?
+ unless @owner.new_record?
+ primary_key = @reflection.options[:primary_key] || :id
+ record[@reflection.primary_key_name] = @owner.send(primary_key)
+ end
end
end