Method: LazyFind::ActiveRecord::FinderMethods#first

Defined in:
lib/lazy_find/active_record/finder_methods.rb

#first(attr = nil) ⇒ Object

Find the first record (or first N records if a parameter is supplied). If no order is defined it will order by primary key.

Person.first # returns the first object fetched by SELECT * FROM people ORDER BY people.id LIMIT 1
Person.where(["user_name = ?", user_name]).first
Person.where(["user_name = :u", { u: user_name }]).first
Person.order("created_on DESC").offset(5).first
Person.first(:email => "jenorish@gmail") # returns the first three objects fetched by SELECT * FROM people WHERE email= '[email protected]'  ORDER BY people.id LIMIT 3


14
15
16
17
# File 'lib/lazy_find/active_record/finder_methods.rb', line 14

def first(attr = nil)
   return super(attr) if attr.blank? || attr.class == Fixnum 
   lazy_find(attr,:first)
end