vendor/bundle/gems/activerecord-4.0.0/lib/active_record/relation.rb
# Updates all records with details given if they match a set of conditions supplied, limits and order can
# also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the
# database. It does not instantiate the involved models and it does not trigger Active Record callbacks
# or validations.
#
# ==== Parameters
#
# * +updates+ - A string, array, or hash representing the SET part of an SQL statement.
#
# ==== Examples
#
#   # Update all customers with the given attributes
#   Customer.update_all wants_email: true
#
#   # Update all books with 'Rails' in their title
#   Book.where('title LIKE ?', '%Rails%').update_all(author: 'David')
#
#   # Update all books that match conditions, but limit it to 5 ordered by date
#   Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(author: 'David')
Updates all records with details given if they match a set of conditions supplied, limits and order can
also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the
database. It does not instantiate the involved models and it does not trigger Active Record callbacks
or validations.

Parameters

+updates+ - A string, array, or hash representing the SET part of an SQL statement.

Examples

Update all customers with the given attributes
Customer.update_all wants_email: true




Updates all records with details given if they match a set of conditions supplied limits and order can also be supplied . This method constructs a single SQL UPDATE statement and sends it straight to the database . It does not instantiate the involved models and it does not trigger Active Record callbacks or validations . Parameters + updates + - A string array or hash representing the SET part of an SQL statement . Examples Update all customers with the given attributes Customer . update_all wants_email : true
def update_all(updates)
      raise ArgumentError, "Empty list of attributes to change" if updates.blank?
      stmt = Arel::UpdateManager.new(arel.engine)
      stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates))
      stmt.table(table)
      stmt.key = table[primary_key]
      if with_default_scope.joins_values.any?
        @klass.connection.join_to_update(stmt, arel)
      else
        stmt.take(arel.limit)
        stmt.order(*arel.orders)
        stmt.wheres = arel.constraints
      end
      @klass.connection.update stmt, 'SQL', bind_values
    end
def update_all ( updates ) raise ArgumentError , "Empty list of attributes to change" if updates . blank? stmt = Arel :: UpdateManager . new ( arel . engine ) stmt . set Arel . sql ( @klass . send ( :sanitize_sql_for_assignment , updates ) ) stmt . table ( table ) stmt . key = table [ primary_key ] if with_default_scope . joins_values . any? @klass . connection . join_to_update ( stmt , arel ) else stmt . take ( arel . limit ) stmt . order ( * arel . orders ) stmt . wheres = arel . constraints end @klass . connection . update stmt , 'SQL' , bind_values end
Updates all records with details given if they match a set of conditions supplied, limits and order can
also be supplied.
Updates all records with details given if they match a set of conditions supplied limits and order can also be supplied .
updates
<not_specific>