Skip to content

"Redundant all" is too naive #347

@zverok

Description

@zverok

I am not sure whether it should be reported as style guide problem, or rubocop-rails problem, but it is a problem :)

Basically, the styleguide claims and the cop supports this claim, that those statements are equivalent:

User.all.<anymethod>
# and
User.<anymethod>

user.articles.all.<anymethod>
# and
user.articles.<anymethod>

The latter is incorrect at least in a case of delete_all (which I shoot myself in a foot with just recently, after update to the latest rubocop-rails):

E.g.:

  • user.articles.all.delete_all = DELETE FROM articles WHERE user_id=1 (delete articles in this scope)
  • user.articles.delete_all = UPDATE articles WHERE user_id=1 SET user_id=NULL (remove articles of this scope from the collection "articles of this user")

Which is... Quite a difference. I love Rails and its conventions 😍

So... Probably both the style guide and the cop should be much more cautious here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions