class

Marten::DB::Field::Base

Inherits Reference / Object

Abstract base field implementation.

Constructors

new(id : ::String, primary_key : ::Bool = false, blank : ::Bool = false, null : ::Bool = false, unique : ::Bool = false, index : ::Bool = false, db_column : ::String | Symbol | Nil = nil)
Source

Instance methods

blank?

Returns a boolean indicating whether the field can be blank validation-wise.

Source
db_column

Returns the name of the column associated with the considered field.

Source
db_column!

Returns a mandatory non-nil version of the DB column (and raise otherwise).

Source
db_column?

Returns true if the field is associated with an in-DB column.

Source
default

Returns the default value of the field if any.

Source
empty_value?(value) : ::Bool

Returns true if the value is considered empty by the field.

Source
from_db(value)

Converts the raw DB value to the corresponding field value.

Source
from_db_result_set(result_set : ::DB::ResultSet)

Extracts the field value from a DB result set and returns the right object corresponding to this value.

Source
getter_value?(value) : ::Bool

Returns true if true should be returned for getter?-like methods for the field.

Usually, true would be returned for values that are truthy and not empty, but this logic can be overridden on a per-field implementation basis.

Source
id

Returns the ID of the field used in the associated model.

Source
index?

Returns true if an index should be created at the database level for the field.

Source
null?

Returns a boolean indicating whether the field can be null at the database level.

Source
prepare_save(record, new_record = false)

Runs pre-save logic for the specific field and record at hand.

This method does nothing by default but can be overridden for specific fields that need to set values on the model instance before save or perform any pre-save logic.

Source
primary_key?

Returns a boolean indicating whether the field is a primary key.

Source
relation?

Returns true if the field is a relation.

By default this method will always return false. It should be overriden if the field is intended to handle a relation with another model (eg. like many to one or one to one fields).

Source
relation_name

Returns the name of the relation on the model associated with the field.

This method will raise a NotImplementedError exception by default and should only be overriden if the #relation? method returns true (this is the case for fields such as many to one, one to one, etc).

Source
to_column

Returns a migration column object corresponding to the field at hand.

Source
to_db(value) : ::DB::Any

Converts the field value to the corresponding DB value.

Source
truthy_value?(value)

Returns true if the value is considered truthy by the field.

Source
unique?

Returns a boolean indicating whether the field value should be unique throughout the associated table.

Source
validate(record, value)

Runs custom validation logic for a specific model field and model object.

This method should be overriden for each field implementation that requires custom validation logic.

Source