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_all #4

Merged
merged 4 commits into from
Nov 28, 2018
Merged

Implement update_all #4

merged 4 commits into from
Nov 28, 2018

Conversation

khiav223577
Copy link
Owner

update_all (expected_number, updates)

Behaves like ActiveRecord::Relation#update_all but add an additional constrain that the number of affected rows equals to what you specify.

Parameters

  • expected_number - The number of rows that you expect to be updated.
  • updates - A string, array, or hash representing the SET part of an SQL statement.

Examples

User.where(id: [1, 2]).atomically.update_all(2, name: '')
# => 2

User.where(id: [1, 2, 3]).atomically.update_all(2, name: '')
# => 0

@khiav223577 khiav223577 merged commit 91edce2 into master Nov 28, 2018
@khiav223577 khiav223577 deleted the feature/update_all branch November 28, 2018 06:42
# 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