method

update_counters

Importance_1
v7.0.0 - Show latest stable - 0 notes - Class: ActiveRecord::Relation
update_counters(counters) public

Updates the counters of the records in the current relation.

Parameters

  • counter - A Hash containing the names of the fields to update as keys and the amount to update as values.

  • :touch option - Touch the timestamp columns when updating.

  • If attributes names are passed, they are updated along with update_at/on attributes.

Examples

# For Posts by a given author increment the comment_count by 1.
Post.where(author_id: author.id).update_counters(comment_count: 1)
Show source
Register or log in to add new notes.