Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement update #3

Merged
merged 15 commits into from
Nov 27, 2018
Merged

Implement update #3

merged 15 commits into from
Nov 27, 2018

Conversation

khiav223577
Copy link
Owner

update

Updates the attributes of the model from the passed-in hash and saves the record. The difference between this method and ActiveRecord#update is that it will add extra WHERE conditions to prevent race condition.

Example:

class Arena < ApplicationRecord
  def atomically_close!
    atomically.update(closed_at: Time.now)
  end

  def close!
    update(closed_at: Time.now)
  end
end
# arena.atomically_close!
UPDATE `arenas` SET `arenas`.`closed_at` = '2018-11-27 03:44:25', `updated_at` = '2018-11-27 03:44:25' 
WHERE `arenas`.`id` = 1752 AND `arenas`.`closed_at` IS NULL

# arena.close!
UPDATE `arenas` SET `arenas`.`closed_at` = '2018-11-27 03:44:25', `updated_at` = '2018-11-27 03:44:25' 
WHERE `arenas`.`id` = 1752

@khiav223577 khiav223577 merged commit 7979e1e into master Nov 27, 2018
@khiav223577 khiav223577 deleted the feature/update branch November 27, 2018 07:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant