#5168·devise

Use `exists?` instead of `find_first` in boolean checking

Author: DijkztraCreated Nov 29, 2019Updated Feb 13, 2026

Environment

  • Ruby 2.4.4
  • Rails 5.2.0
  • Devise 3.5.6

Current behaviour

Some boolean checking query use find_first method. find_first will create a select * query when run, then the result will automatically converted into ActiveRecord object by Rails.

https://apidock.com/rails/v4.0.2/ActiveRecord/FinderMethods/find_first

Location

lib/devise/models/rememberable.rb:150 lib/devise/token_generator.rb:22

Expected behavior

Using exists? method make the resulting query is select 1 and ActiveRecord doesn't need to convert the query result into a model object. Also, both Mongoid and Rails have exists? support.

https://apidock.com/rails/ActiveRecord/Base/exists%3F/class