diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-17 06:40:38 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-17 10:46:19 -0300 |
commit | ee439895759b38431ad025f3c234831f30dadcdb (patch) | |
tree | 5d4cb9e79617a0a41ee71cb11caef14b83a2eb6b /activerecord/lib | |
parent | 07c8055dc05c954c7f61006fcad85997be2c04a1 (diff) | |
download | rails-ee439895759b38431ad025f3c234831f30dadcdb.tar.gz rails-ee439895759b38431ad025f3c234831f30dadcdb.tar.bz2 rails-ee439895759b38431ad025f3c234831f30dadcdb.zip |
Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmt
Fix collection= on hm:t join models when unsaved
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 53d49fef2e..ce81333aa9 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -38,6 +38,20 @@ module ActiveRecord super end + def concat_records(records) + ensure_not_nested + + records = super + + if owner.new_record? && records + records.flatten.each do |record| + build_through_record(record) + end + end + + records + end + def insert_record(record, validate = true, raise = false) ensure_not_nested |