diff options
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.rb | 17 |
1 files changed, 13 insertions, 4 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 f299f51466..9f74d57c4d 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -22,12 +22,21 @@ module ActiveRecord end end + def <<(*records) + unless @owner.new_record? + records.flatten.each do |record| + raise_on_type_mismatch(record) + record.save! if record.new_record? + end + end + + super + end + protected - def insert_record(record, force = true, validate = true) - if record.new_record? - return unless save_record(record, force, validate) - end + def insert_record(record, validate = true) + return if record.new_record? && !record.save(:validate => validate) through_association = @owner.send(@reflection.through_reflection.name) through_association.create!(construct_join_attributes(record)) |