Skip to content

Commit ded30ad

Browse files
committed
Add section for where.not with multiple attributes
Issue:rubocop/rubocop-rails#565
1 parent 14783aa commit ded30ad

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,21 @@ Customer.where("purchases_count > :min AND purchases_count <= :max", min: 0, max
10861086

10871087
NOTE: Rails 6.0 or later is required for endless range Ruby 2.6 syntax, and Rails 6.0.3 for beginless range Ruby 2.7 syntax.
10881088

1089+
=== `where.not` with multiple attributes
1090+
1091+
Avoid passing multiple attributes to `where.not`. Rails logic in this case has changed in Rails 6.1 and
1092+
will now yield results matching either of those conditions,
1093+
e.g. `where.not(status: 'active', plan: 'basic')` would return records with active status when the plan is business.
1094+
1095+
[source, ruby]
1096+
----
1097+
# bad
1098+
User.where.not(status: 'active', plan: 'basic')
1099+
1100+
# good
1101+
User.where.not('status = ? AND plan = ?', 'active', 'basic')
1102+
----
1103+
10891104
== Migrations
10901105

10911106
=== Schema Version [[schema-version]]

0 commit comments

Comments
 (0)