A
A
Anton Misyagin2015-06-30 11:15:51
Ruby on Rails
Anton Misyagin, 2015-06-30 11:15:51

Rails updating multiple records in one request?

Hello. There are notifications for users on the site. Notifications have a "read" field. If the user does not enter notifications for a long time, then they accumulate there and when the page is opened, the script sets the field to true one by one. Even about 50 records are processed noticeably. Those. there are about 50 UPDATE queries to the database. Is it possible to bulk apply an attribute?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2015-06-30
@2ord

If possible, use conditional update of records with one query: user.posts.where
(visited: false).update_all(visited: true)
ActiveRecord update_all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question