aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index ba2ac7908e..0c31f0f57e 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -243,13 +243,16 @@ module ActiveRecord
#
# ==== Examples
#
- # # Insert multiple records, performing an upsert when records have duplicate ISBNs
+ # # Given a unique index on <tt>books.isbn</tt> and the following record:
+ # Book.create!(title: 'Rework', author: 'David', isbn: '1')
+ #
+ # # Insert multiple records, allowing new records with the same ISBN
+ # # as an existing record to overwrite the existing record.
# # ('Eloquent Ruby' will overwrite 'Rework' because its ISBN is duplicate)
# Book.upsert_all([
- # { title: 'Rework', author: 'David', isbn: '1' },
- # { title: 'Eloquent Ruby', author: 'Russ', isbn: '1' }
- # ],
- # unique_by: { columns: %w[ isbn ] })
+ # { title: 'Eloquent Ruby', author: 'Russ', isbn: '1' },
+ # { title: 'Clean Code', author: 'Robert', isbn: '2' }
+ # ], unique_by: { columns: %w[ isbn ] })
#
def upsert_all(attributes, returning: nil, unique_by: nil)
InsertAll.new(self, attributes, on_duplicate: :update, returning: returning, unique_by: unique_by).execute