Skip to content

Use find_by instead of where + first

Arturo Herrero requested to merge 211877-find-by-instead-of-where-first into master

What does this MR do?

Update usages of where.first and change them to use find_by instead.

# bad
User.where(name: 'Bruce').first
User.where(name: 'Bruce').take

# good
User.find_by(name: 'Bruce')

I've tried to enforce this automatically with Rails/FindBy in the .rubocop file which is supposed to be enabled by default but doesn't work at all.

References:

I've modified this with the help of Atom:

Screen_Shot_2020-03-24_at_15.14.01

Closes #211877 (closed)

Merge request reports