Does the update_all method in ActiveRecord call the number of rows?

I want to set the "lock" column in the row only if it is not already set. Most likely, race conditions and performance are important, so you need to do this in one request. I think the solution should look like this:

class MyModel
  def lock(worker)
    cnt = MyModel.where(id: self.id, lock: nil).update_all(:lock=>worker.name)
    cnt == 1
  end
end

Does the method really update_allreturn the number of rows executed in the same way as in the DataMapper?

+5
source share
1 answer

Yes, this happens in ActiveRecord, as in DataMapper

+6
source

All Articles