From c9452aee092d3964b3ed6c5aa2cb2833b08cb394 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 18 Mar 2020 07:08:33 -0700 Subject: [PATCH] Better first [skip ci] --- lib/searchkick/relation.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 43aa170..d450afa 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -9,7 +9,7 @@ module Searchkick :took, :error, :model_name, :entry_name, :total_count, :total_entries, :current_page, :per_page, :limit_value, :total_pages, :num_pages, :offset_value, :previous_page, :prev_page, :next_page, :first_page?, :last_page?, - :out_of_range?, :hits, :response, :to_a, :first, :highlights, :group_by, :misspellings?, :with_highlights, + :out_of_range?, :hits, :response, :to_a, :highlights, :group_by, :misspellings?, :with_highlights, :none?, :one?, :many? def_delegators :query, :params @@ -118,6 +118,10 @@ module Searchkick limit ? first(limit) : first end + def first(limit = nil) + limit ? self.limit(limit).to_a : self.limit(1).to_a.first + end + # TODO make more efficient if loaded def pluck(*fields) result = load(false) -- libgit2 0.21.0