diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-11-29 15:30:45 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-11-29 15:30:45 -0700 |
commit | 3f16a098452ee5d447142bd9a6f6045cb1fc83b4 (patch) | |
tree | 198bf133418ef4a5b25453fe8f3262017fe4add5 /activerecord/lib/active_record | |
parent | ac26573c6609906c8d5f626e8e17078372cbd0df (diff) | |
parent | 6d0d83a33f59d9415685852cf77818c41e2e2700 (diff) | |
download | rails-3f16a098452ee5d447142bd9a6f6045cb1fc83b4.tar.gz rails-3f16a098452ee5d447142bd9a6f6045cb1fc83b4.tar.bz2 rails-3f16a098452ee5d447142bd9a6f6045cb1fc83b4.zip |
Merge pull request #18155 from bogdan/collection_association_double_element_fix
Bugfix collection association #create method
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index f32dddb8f0..473b80a658 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -414,12 +414,16 @@ module ActiveRecord def replace_on_target(record, index, skip_callbacks) callback(:before_add, record) unless skip_callbacks + + was_loaded = loaded? yield(record) if block_given? - if index - @target[index] = record - else - @target << record + unless !was_loaded && loaded? + if index + @target[index] = record + else + @target << record + end end callback(:after_add, record) unless skip_callbacks |