instance method
first
Ruby on Rails 5.2.8.1
Since v5.2.8.1 Last seen in v6.0.6Available in: v5.2.8.1 v6.0.6
Signature
first()
Returns the first record from the rows collection. If the rows collection is empty, returns nil.
Source
# File activerecord/lib/active_record/result.rb, line 87
def first
return nil if @rows.empty?
Hash[@columns.zip(@rows.first)]
end
Defined in activerecord/lib/active_record/result.rb line 87
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Result