Commit c9452aee092d3964b3ed6c5aa2cb2833b08cb394

Authored by Andrew Kane
1 parent 15cf601c
Exists in relation

Better first [skip ci]

Showing 1 changed file with 5 additions and 1 deletions   Show diff stats
lib/searchkick/relation.rb
... ... @@ -9,7 +9,7 @@ module Searchkick
9 9 :took, :error, :model_name, :entry_name, :total_count, :total_entries,
10 10 :current_page, :per_page, :limit_value, :total_pages, :num_pages,
11 11 :offset_value, :previous_page, :prev_page, :next_page, :first_page?, :last_page?,
12   - :out_of_range?, :hits, :response, :to_a, :first, :highlights, :group_by, :misspellings?, :with_highlights,
  12 + :out_of_range?, :hits, :response, :to_a, :highlights, :group_by, :misspellings?, :with_highlights,
13 13 :none?, :one?, :many?
14 14  
15 15 def_delegators :query, :params
... ... @@ -118,6 +118,10 @@ module Searchkick
118 118 limit ? first(limit) : first
119 119 end
120 120  
  121 + def first(limit = nil)
  122 + limit ? self.limit(limit).to_a : self.limit(1).to_a.first
  123 + end
  124 +
121 125 # TODO make more efficient if loaded
122 126 def pluck(*fields)
123 127 result = load(false)
... ...