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/FindBy autocorrects to not-necessarily-equivalent find_by #1938

Closed
aripollak opened this issue Jun 2, 2015 · 1 comment
Closed

Rails/FindBy autocorrects to not-necessarily-equivalent find_by #1938

aripollak opened this issue Jun 2, 2015 · 1 comment

Comments

@aripollak
Copy link

Something I didn't initially realize when using the new Rails/FindBy cop is that where(...).first is not equivalent to find_by in Rails 4+. The former orders by id by default (and maybe default_scope?), but the latter does not. It doesn't seem like the cop should autocorrect this case. It might not even make sense to match it at all, or if it does, then there should be a caveat about them not necessarily being equivalent.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 3, 2015

Yeah, you're totally right. I'm aware of the difference, but the problem is most people use where().first instead of where().take and they still don't care about the order. Maybe this was a mistake on my part and I should leave an auto-correct only for where().take.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants