aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_through_association.rb
diff options
context:
space:
mode:
authorErnie Miller <ernie@erniemiller.org>2012-09-16 21:23:58 -0400
committerErnie Miller <ernie@erniemiller.org>2012-09-17 09:20:18 -0400
commit610b63288f05bdec677bfd78c546ee085e5184b9 (patch)
treed1ad97c1c759869b4b422965888683ceeee2cae8 /activerecord/lib/active_record/associations/has_many_through_association.rb
parent82efe8943bf6ff12b597987506bf177d66609049 (diff)
downloadrails-610b63288f05bdec677bfd78c546ee085e5184b9.tar.gz
rails-610b63288f05bdec677bfd78c546ee085e5184b9.tar.bz2
rails-610b63288f05bdec677bfd78c546ee085e5184b9.zip
Fix collection= on hm:t join models when unsaved
If assigning to a has_many :through collection against an unsaved object using the collection=[<array_of_items>] syntax, the join models were not properly created, previously.
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb14
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 88ff11f953..d8f14c896c 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -37,6 +37,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