rubocop / rails-style-guide

A community-driven Ruby on Rails style guide
http://rails.rubystyle.guide
6.47k stars 1.06k forks source link

Suggestion: Add description about Active Record redundant `all` #339

Closed masato-bkn closed 1 year ago

masato-bkn commented 1 year ago

I suggest to add description about Active Record redundant all.

I often come across all used as receiver of Active Record query methods.

# bad
User.all.order(:created_at)
User.all.find(id)
User.all.where(id: ids)

# good
User.order(:created_at)
User.find(id)
User.where(id: ids)

In these cases, the output is same with or without all, so I think it's redundant and could be removed.

If there's a positive reaction to this issue, I plan to submit a PR.

koic commented 1 year ago

@masato-bkn There is no issue if the redundant all method call will be removed. Can you open a PR?