aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTim Harper <timcharper@gmail.com>2008-05-13 19:17:40 -0600
committerrick <technoweenie@gmail.com>2008-05-31 13:27:25 -0700
commit0580b31b36c0f7dd1a0f8bdd1b1806e3bd65b22d (patch)
tree8bb596cb3279cf0b703edd6e8a3a70a7b443a082 /activerecord/lib
parentf7015336f66d284cff8ecb89df9f430791ac57ea (diff)
downloadrails-0580b31b36c0f7dd1a0f8bdd1b1806e3bd65b22d.tar.gz
rails-0580b31b36c0f7dd1a0f8bdd1b1806e3bd65b22d.tar.bz2
rails-0580b31b36c0f7dd1a0f8bdd1b1806e3bd65b22d.zip
belongs_to polymorphic association assignments update the foreign_id and foreign_type fields regardless of whether the record being assigned is new or not.
fixes the following scenarios: * I have validates_inclusion_of on the type field for a polymorphic belongs_to association. I assign a new record to the model's polymorphic relationship of the proper type. validation fails because the type field has not been updated. * I replace the value for a ppolymorphic association to a new record of another class. The type field still says its the previous class, and the id field points to the previous record as well. [#191 state:closed]
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations/belongs_to_polymorphic_association.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
index df4ae38f38..d8146daa54 100755
--- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
@@ -7,10 +7,8 @@ module ActiveRecord
else
@target = (AssociationProxy === record ? record.target : record)
- unless record.new_record?
- @owner[@reflection.primary_key_name] = record.id
- @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s
- end
+ @owner[@reflection.primary_key_name] = record.id
+ @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s
@updated = true
end