diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-06-30 22:41:18 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-06-30 23:39:58 +0100 |
commit | 0e225ec583db523a8b7da332eaf689149ed60447 (patch) | |
tree | bb18c8a7b672eb7545c36daba2aba2c0a3ce46c0 /activerecord/lib/active_record/associations/association.rb | |
parent | 6a283d598f243197375266c8b981b66f1b5f10c5 (diff) | |
download | rails-0e225ec583db523a8b7da332eaf689149ed60447.tar.gz rails-0e225ec583db523a8b7da332eaf689149ed60447.tar.bz2 rails-0e225ec583db523a8b7da332eaf689149ed60447.zip |
Assign the association attributes to the associated record before the before_initialize callback of the record runs. Fixes #1842.
Diffstat (limited to 'activerecord/lib/active_record/associations/association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index c3aee90124..daadc8aa81 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -224,6 +224,15 @@ module ActiveRecord def association_class @reflection.klass end + + def build_record(attributes, options) + reflection.build_association(attributes, options) do |record| + record.assign_attributes( + create_scope.except(*record.changed), + :without_protection => true + ) + end + end end end end |