Merge pull request #45662 from ghiculescu/patch-10

Mention `Arel.sql` in `update_all` docs [docs]
This commit is contained in:
Yasuo Honda 2022-07-26 14:14:42 +09:00 committed by GitHub
commit f34fbadc10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -448,7 +448,8 @@ def _exec_scope(...) # :nodoc:
#
# ==== Parameters
#
# * +updates+ - A string, array, or hash representing the SET part of an SQL statement.
# * +updates+ - A string, array, or hash representing the SET part of an SQL statement. Any strings provided will
# be type cast, unless you use `Arel.sql`. (Don't pass user-provided values to `Arel.sql`.)
#
# ==== Examples
#
@ -463,6 +464,9 @@ def _exec_scope(...) # :nodoc:
#
# # Update all invoices and set the number column to its id value.
# Invoice.update_all('number = id')
#
# # Update all books with 'Rails' in their title
# Book.where('title LIKE ?', '%Rails%').update_all(title: Arel.sql("title + ' - volume 1'"))
def update_all(updates)
raise ArgumentError, "Empty list of attributes to change" if updates.blank?