From fc8392e51f90881b1c7c910c5e17823c55f0577b Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Mon, 22 Jan 2018 16:53:32 +0300 Subject: [PATCH] Refactor History::FinderMethods: use base implementation. It also makes `first_by_friendly_id` better because base implementation in `FriendlyId::FinderMethods` uses `find_by` which is optimized in Rails 4.2 (so called "Adequate Record"). --- lib/friendly_id/history.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/friendly_id/history.rb b/lib/friendly_id/history.rb index 5e3ba35d9..8abb78283 100644 --- a/lib/friendly_id/history.rb +++ b/lib/friendly_id/history.rb @@ -86,14 +86,13 @@ module FinderMethods include ::FriendlyId::FinderMethods def exists_by_friendly_id?(id) - where(arel_table[friendly_id_config.query_field].eq(id)).exists? || joins(:slugs).where(slug_history_clause(id)).exists? + super || joins(:slugs).where(slug_history_clause(id)).exists? end private def first_by_friendly_id(id) - matching_record = where(friendly_id_config.query_field => id).first - matching_record || slug_table_record(id) + super || slug_table_record(id) end def slug_table_record(id)