first

first(limit = nil) Instance Public methods 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 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(3) # returns the first three objects fetched by SELECT * FROM people LIMIT 3 Ra

first!

first!() Instance Public methods Same as first but raises ActiveRecord::RecordNotFound if no record is found. Note that first! accepts no arguments.

forty_two

forty_two() Instance Public methods Find the forty-second record. Also known as accessing âthe redditâ. If no order is defined it will order by primary key. Person.forty_two # returns the forty-second object fetched by SELECT * FROM people Person.offset(3).forty_two # returns the forty-second object from OFFSET 3 (which is OFFSET 44) Person.where(["user_name = :u", { u: user_name }]).forty_two

forty_two!

forty_two!() Instance Public methods Same as forty_two but raises ActiveRecord::RecordNotFound if no record is found.

fourth

fourth() Instance Public methods Find the fourth record. If no order is defined it will order by primary key. Person.fourth # returns the fourth object fetched by SELECT * FROM people Person.offset(3).fourth # returns the fourth object from OFFSET 3 (which is OFFSET 6) Person.where(["user_name = :u", { u: user_name }]).fourth

fourth!

fourth!() Instance Public methods Same as fourth but raises ActiveRecord::RecordNotFound if no record is found.

last

last(limit = nil) Instance Public methods Find the last record (or last N records if a parameter is supplied). If no order is defined it will order by primary key. Person.last # returns the last object fetched by SELECT * FROM people Person.where(["user_name = ?", user_name]).last Person.order("created_on DESC").offset(5).last Person.last(3) # returns the last three objects fetched by SELECT * FROM people. Take note that in that last case, the results are sorted in ascending order

last!

last!() Instance Public methods Same as last but raises ActiveRecord::RecordNotFound if no record is found. Note that last! accepts no arguments.

second

second() Instance Public methods Find the second record. If no order is defined it will order by primary key. Person.second # returns the second object fetched by SELECT * FROM people Person.offset(3).second # returns the second object from OFFSET 3 (which is OFFSET 4) Person.where(["user_name = :u", { u: user_name }]).second

second!

second!() Instance Public methods Same as second but raises ActiveRecord::RecordNotFound if no record is found.