module ActiveRecord::FindOnly
Constants
- VERSION
Public Instance Methods
find_only()
click to toggle source
Gives the only record that matches the criteria. If no record matches the criteria, nil is returned. If more than one record matches the criteria, TooManyRecords
is raised.
# File lib/active_record/find_only.rb, line 11 def find_only found_records = take(2) if found_records.length > 1 raise TooManyRecords end found_records[0] end
find_only!()
click to toggle source
Gives the only record that matches the criteria. If no record matches the criteria, RecordNotFound is raised. If more than one record matches the criteria, TooManyRecords
is raised.
# File lib/active_record/find_only.rb, line 22 def find_only! find_only || raise_record_not_found_exception! end