module Marten::DB::Model::Table

Direct including types

Defined in:

marten/db/model/table.cr
marten/db/model/table/field_context.cr
marten/db/model/table/reverse_relation_context.cr

Macro Summary

Instance Method Summary

Macro Detail

macro field(*args, **kwargs) #

[View source]
macro with_timestamp_fields #

Allows to automatically configure creation and update timestamp fields.

This macro will contribute two model fields to the models it is applied to: one created_at field containing the creation time of the record, and one updated_at field containing the update time of the record (which is also refreshed every time the model is updated).


[View source]

Instance Method Detail

def get_field_value(field_name : String | Symbol) #

Allows to read the value of a specific field.

This methods returns the value of the field corresponding to field_name. If the passed field_name doesn't match any existing field, a Marten::DB::Errors::UnknownField exception is raised.


[View source]
def get_related_object(relation_name : String | Symbol) #

Allows to return the record associated with a specific relation name.

If no record is associated with the specified relation (eg. if the corresponding field is nullable), then nil is returned. If the specified relation name is not defined on the model, then a Marten::DB::Errors::UnknownField exception is raised.


[View source]
def inspect(io) #

[View source]
def pk #

Returns the primary key value.


[View source]
def pk! #

Returns the primary key value or raise NilAssertionError.


[View source]
def pk=(val) #

Allows to set the primary key value.


[View source]
def pk? : Bool #

Returns true if a primary key value is set on the record.


[View source]
def set_field_value(field_name : String | Symbol, value : Field::Any | Model) #

Allows to set the value of a specific field.

If the passed field_name doesn't match any existing field, a Marten::DB::Errors::UnknownField exception will be raised.


[View source]
def set_field_values(values : Hash | NamedTuple) #

Allows to set the values of multiple fields.

If one of the specified field names doesn't match any existing field, a Marten::DB::Errors::UnknownField exception will be raised.


[View source]
def set_field_values(**values) #

Allows to set the values of multiple fields.

If one of the specified field names doesn't match any existing field, a Marten::DB::Errors::UnknownField exception will be raised.


[View source]
def to_s(io) #

[View source]