Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/activerecord/one/relation_ext.rb
Instance Method Summary collapse
-
#one! ⇒ Object
Asserts that the collection contains exactly one record, and returns it.
Instance Method Details
#one! ⇒ Object
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.
7 8 9 10 11 12 13 14 15 16 |
# 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 |