Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rails 6 deprecates where.not as NOR & Rails 6.1 as NAND #565

Closed
jsolas opened this issue Sep 27, 2021 · 6 comments
Closed

Rails 6 deprecates where.not as NOR & Rails 6.1 as NAND #565

jsolas opened this issue Sep 27, 2021 · 6 comments
Labels
feature request Request for new functionality

Comments

@jsolas
Copy link

jsolas commented Sep 27, 2021

Currently if you use Rails 5.2 you can do for example: Post.where.not(source_type: "Feed", source_id: 100) and if we do the same in Rails 6.0.0.rc1 shows us the warning NOT conditions will no longer behave as NOR in Rails 6.1.To continue using NOR conditions, NOT each conditions manually.

This will make the migration process to Rails 6 difficult and it will not be correct to continue using the conditions as rails 5.2 does.

Describe the solution you'd like

Create a cop prohibiting the use of where.not with two arguments. I would like to contribute by creating it

Additional context

This is the Rails pull request where it was made rails/rails#36029
More details of the change in this article https://www.bigbinary.com/blog/rails-6-deprecates-where-not-working-as-nor-and-will-change-to-nand-in-rails-6-1

@dvandersluis dvandersluis transferred this issue from rubocop/rubocop Sep 27, 2021
@andyw8
Copy link
Contributor

andyw8 commented Sep 27, 2021

Post.where (source_type: "Feed", source_id: 100)

Did you mean to write Post.where.not(source_type: "Feed", source_id: 100) ?

@andyw8
Copy link
Contributor

andyw8 commented Sep 27, 2021

An alternative way to enforce this would be to configure Rails to raise on deprecation warnings:

config.active_support.deprecation = :raise

@jsolas
Copy link
Author

jsolas commented Sep 27, 2021

Post.where (source_type: "Feed", source_id: 100)

Did you mean to write Post.where.not(source_type: "Feed", source_id: 100) ?

yes, sorry, fixed!

@koic koic added the feature request Request for new functionality label Sep 28, 2021
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Nov 20, 2021
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Nov 20, 2021
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Nov 20, 2021
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Nov 20, 2021
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Nov 21, 2021
@denzelem
Copy link

@jsolas Do you already have started with implementing this cop or do you have time capacities in the near future for it? Otherwise I can take care about it.

@andyw8 Would you be willing to merge such a cop? I've seen you commented in rubocop/rails-style-guide#296 (comment), that you consider a chained not as bad, too. So what do you expect from this cop?

@pirj
Copy link
Member

pirj commented Jan 13, 2022

@denzelem A cop would surely be nice to have. A PR is welcome.

So what do you expect from this cop?

I'd say the cop should raise an offence for multiple attributes. And tolerate chained where.not as a configurable option.

@pirj
Copy link
Member

pirj commented Jan 13, 2022

An alternative way to enforce this would be to configure Rails to raise on deprecation warnings:

    config.active_support.deprecation = :raise

It's not always feasible I suppose, e.g. if there are other deprecation warnings.

nhasselmeyer added a commit to nhasselmeyer/rubocop-rails that referenced this issue Feb 10, 2022
nhasselmeyer added a commit to nhasselmeyer/rubocop-rails that referenced this issue Feb 10, 2022
Rails 6.1 changed how where.not works with multiple hash arguments.

This cop identifies places where where.not is used with multiple hash
arguments. It doesn't suggest corrections because depending on the rails
version, different behaviours may be correct.

```ruby
# bad
User.where.not(trashed: true, role: 'admin')

# good
User.where.not('trashed = ? OR role = ?', true, 'admin')
```
nhasselmeyer added a commit to nhasselmeyer/rubocop-rails that referenced this issue Feb 10, 2022
Rails 6.1 changed how where.not works with multiple hash arguments.

This cop identifies places where where.not is used with multiple hash
arguments. It doesn't suggest corrections because depending on the rails
version, different behaviours may be correct.

```ruby
# bad
User.where.not(trashed: true, role: 'admin')

# good
User.where.not('trashed = ? OR role = ?', true, 'admin')
```
nhasselmeyer added a commit to nhasselmeyer/rubocop-rails that referenced this issue Feb 10, 2022
Rails 6.1 changed how where.not works with multiple hash arguments.

This cop identifies places where where.not is used with multiple hash
arguments. It doesn't suggest corrections because depending on the rails
version, different behaviours may be correct.

```ruby
# bad
User.where.not(trashed: true, role: 'admin')

# good
User.where.not('trashed = ? OR role = ?', true, 'admin')
```
nhasselmeyer added a commit to nhasselmeyer/rubocop-rails that referenced this issue Mar 15, 2022
Rails 6.1 changed how where.not works with multiple hash arguments.

This cop identifies places where where.not is used with multiple hash
arguments. It doesn't suggest corrections because depending on the rails
version, different behaviours may be correct.

```ruby
# bad
User.where.not(trashed: true, role: 'admin')

# good
User.where.not('trashed = ? OR role = ?', true, 'admin')
```
nhasselmeyer added a commit to nhasselmeyer/rubocop-rails that referenced this issue Aug 3, 2022
Rails 6.1 changed how `where.not` works with multiple hash arguments.

This cop identifies places where `where.not` is used with multiple hash
arguments. It doesn't suggest corrections because depending on the rails
version, different behaviours may be correct.

```ruby
# bad
User.where.not(trashed: true, role: 'admin')

# good
User.where.not('trashed = ? OR role = ?', true, 'admin')
```
@koic koic closed this as completed in 7d03a57 Sep 25, 2022
koic added a commit that referenced this issue Sep 25, 2022
…le-arguments

[Fix #565] Add cop Rails/WhereNotWithMultipleConditions
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Apr 11, 2023
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

No branches or pull requests

5 participants