Describe unsafe usage of invert_where method [ci skip]
#42118
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
invert_wheremethod has been added by #40249.This pull request adds documentation of unsafe usage of
invert_where.As #40249 (comment), this method is dangerous.
Because it inverts all conditions before
invert_wherecall.For example
On the last line,
User.where(role: 'admin').inactiveinvertswhere(role: 'admin')unexpectedly.But the current documentation only describes a single
wheremethod call case. So we can understand howwhere(...).invert_whereworks, but cannot understand howwhere(...).where(...).invert_whereworks from the document.This behavior can become a bug, so the documentation should describe the behavior.
By the way, I'm wondering if adding it should be reverted. Because it is too dangerous IMO. I will not use this method for my project to avoid problems.
But I think it needs the document to describe the risk at least.
I also opened an issue to rubocop-rails for this method. rubocop/rubocop-rails#470