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?
source
share