Exception: ActiveRecord::SoleRecordExceeded

Inherits:
ActiveRecordError show all
Defined in:
activerecord/lib/active_record/errors.rb

Overview

Raised when Active Record finds multiple records but only expected one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record = nil) ⇒ SoleRecordExceeded

Returns a new instance of SoleRecordExceeded.


149
150
151
152
# File 'activerecord/lib/active_record/errors.rb', line 149

def initialize(record = nil)
  @record = record
  super "Wanted only one #{record&.name || "record"}"
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.


147
148
149
# File 'activerecord/lib/active_record/errors.rb', line 147

def record
  @record
end