Module: ActiveRecord::BulkInsert
- Defined in:
- lib/active_record/bulk_insert.rb
Instance Method Summary collapse
Instance Method Details
#bulk_insert(objects, ignore_new_record: true) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record/bulk_insert.rb', line 8 def bulk_insert(objects, ignore_new_record: true) result = objects.group_by(&:new_record?).map { |is_new_record, records| if is_new_record if ignore_new_record records.each(&:save!) else insert_all!(build_attributes(records)) end else upsert_all(build_attributes(records)) end records } result.flatten end |