diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-12-05 07:08:51 -0800 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-12-05 07:08:51 -0800 |
commit | 23d555a0abcbe5bb143928d33aaf66b38f63338b (patch) | |
tree | 9701a5c8a35828fd619a3af91042e2cde432f6f4 /activerecord/lib | |
parent | f0c58621f104492aa1c2b6cb13ecb2d6c60541fa (diff) | |
parent | f1a646fa74290db32fb52bb373791891ab73d693 (diff) | |
download | rails-23d555a0abcbe5bb143928d33aaf66b38f63338b.tar.gz rails-23d555a0abcbe5bb143928d33aaf66b38f63338b.tar.bz2 rails-23d555a0abcbe5bb143928d33aaf66b38f63338b.zip |
Merge pull request #12646 from severin/polymorphic_belongs_to_touch
polymorphic belongs_to association with touch: true updates old record correctly
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/belongs_to.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index ac387d377d..e8e36e7cd0 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -91,7 +91,13 @@ module ActiveRecord::Associations::Builder old_foreign_id = o.changed_attributes[foreign_key] if old_foreign_id - klass = o.association(name).klass + association = o.association(name) + reflection = association.reflection + if reflection.polymorphic? + klass = o.public_send("#{reflection.foreign_type}_was").constantize + else + klass = association.klass + end old_record = klass.find_by(klass.primary_key => old_foreign_id) if old_record |