class PgORM::Error::RecordInvalid

Overview

Raised when a record fails validation.

This exception includes the model instance and all validation errors.

Example

user = User.new(name: "")
begin
  user.save!
rescue PgORM::Error::RecordInvalid => e
  puts e.message # => "User has an invalid field. `name` can't be blank"
  e.errors.each do |error|
    puts "#{error[:field]}: #{error[:message]}"
  end
end

Defined in:

pg-orm/errors.cr

Constructors

Instance Method Summary

Instance methods inherited from class PgORM::Error

message : String? message

Constructor methods inherited from class PgORM::Error

new(message : String | Nil = "") new

Constructor Detail

def self.new(model : PgORM::Base, message = nil) #

[View source]

Instance Method Detail

def errors : Array(NamedTuple(field: Symbol, message: String)) #

[View source]
def model : Base #

[View source]