module

Ktistec::Model

Constants

Log = ::Log.for("database")

logging in this module is related to database query performance.

Constructors

new(properties : Hash(String, Any), *, _strict : Bool = false) forall Any

Initializes a new instance.

Specified properties are assigned via setter methods. If a property lacks a setter the property is read-only and cannot be assigned. Non-nilable properties must be assigned.

To allow initialization of multiple models from a single collection of properties, initialize ignores specified properties that do not exist on the model. Specify _strict: true to change this behavior to raise an error instead.

Source
new(*, _strict : Bool = false, **properties)

Initializes a new instance.

Specified properties are assigned via setter methods. If a property lacks a setter the property is read-only and cannot be assigned. Non-nilable properties must be assigned.

To allow initialization of multiple models from a single collection of properties, initialize ignores specified properties that do not exist on the model. Specify _strict: true to change this behavior to raise an error instead.

Source

Instance methods

==(other : self)

Returns true if all persistent properties are equal.

Source
==(other)

Returns false.

Source
_run_validations
Source
_save_model(skip_validation = false)
Source
_serialize_graph(nodes, seen = Set(UInt64).new, association = nil, index = nil, skip_associated = false)
Source
assign(properties : Hash(String, Any), *, _strict : Bool = false) forall Any

Bulk assigns properties.

Specified properties are assigned via setter methods. If a property lacks a setter the property is read-only and cannot be assigned.

To allow assignment of multiple models from a single collection of properties, assign ignores specified properties that do not exist on the model. Specify _strict: true to change this behavior to raise an error instead.

Source
assign(*, _strict : Bool = false, **properties)

Bulk assigns properties.

Specified properties are assigned via setter methods. If a property lacks a setter the property is read-only and cannot be assigned.

To allow assignment of multiple models from a single collection of properties, assign ignores specified properties that do not exist on the model. Specify _strict: true to change this behavior to raise an error instead.

Source
changed!(*properties : Symbol)
Source
changed?
Source
changed?(*properties : Symbol)
Source
clear_changed!
Source
clear_changed!(*properties : Symbol)
Source
destroy

Destroys the instance.

Source
destroyed?
Source
errors
Source
hash(hasher)

Computes the hash for this instance.

Source
id=(id : Int64 | Nil)
Source
inspect(io : IO)
Source
new_record?
Source
reload!

Reloads the properties from the database.

Only reloads the persistent properties. Does not trigger any side effects. Does not ensure that the instance's state is otherwise valid.

Source
save(skip_validation = false, skip_associated = false)

Saves the instance.

Source
serialize_graph(skip_associated = false)
Source
table_name

Returns the table name.

Source
to_h
Source
to_json(json : JSON::Builder)
Source
to_s(io : IO)
Source
update_property(property, value)

Updates and persists property value.

This method is meant for simple state changes -- it does not validate model state or run before and after actions! Prefer assign/save methods.

Source
valid?(skip_associated = false)

Returns true if the instance is valid.

Source
validate(skip_associated = false)

Validates the instance and returns any errors.

Source

Macros

belongs_to(name, primary_key = id, foreign_key = nil, class_name = nil, inverse_of = nil)

Specifies a one-to-one association with another model.

Source
derived(decl, *, aliased_to)

Specifies a property that is derived from another property.

Source
has_many(name, primary_key = id, foreign_key = nil, class_name = nil, inverse_of = nil)

Specifies a one-to-many association with another model.

Source
has_one(name, primary_key = id, foreign_key = nil, class_name = nil, inverse_of = nil)

Specifies a one-to-one association with another model.

Source
validates(property, &block)

Adds a validation to a property on an instance.

validates xyz { "is blank" if xyz.blank? }
Source

Nested types