class ActiveRecord::Relation

Public Instance Methods

one!() click to toggle source

Asserts that the collection contains exactly one record, and returns it.

If the collection is empty, it raises ActiveRecord::NoRecordFound. If the collection contains more than one record, it raises ActiveRecord::MultipleRecordsFound.

# File lib/activerecord/one/relation_ext.rb, line 7
def one!
  case size
  when 0
    raise ActiveRecord::NoRecordFound
  when 1
    first
  else
    raise ActiveRecord::MultipleRecordsFound
  end
end