Returns a boolean indicating whether the field is a primary key.
abstract class Marten::DB::Field::Base
- Marten::DB::Field::Base
- Reference
- Object
Overview
Abstract base field implementation.
Direct Known Subclasses
- Marten::DB::Field::BigInt
- Marten::DB::Field::Bool
- Marten::DB::Field::Date
- Marten::DB::Field::DateTime
- Marten::DB::Field::File
- Marten::DB::Field::Float
- Marten::DB::Field::Int
- Marten::DB::Field::ManyToMany
- Marten::DB::Field::ManyToOne
- Marten::DB::Field::OneToOne
- Marten::DB::Field::String
- Marten::DB::Field::Text
- Marten::DB::Field::UUID
Defined in:
marten/db/field/base.crConstructors
Instance Method Summary
-
#blank? : Bool
Returns a boolean indicating whether the field can be blank validation-wise.
-
#db_column
Returns the name of the column associated with the considered field.
-
#db_column! : ::String
Returns a mandatory non-
nil
version of the DB column (and raise otherwise). -
#db_column?
Returns
true
if the field is associated with an in-DB column. -
#default
Returns the default value of the field if any.
-
#from_db(value)
Converts the raw DB value to the corresponding field value.
-
#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.
-
#id : String
Returns the ID of the field used in the associated model.
-
#index? : Bool
Returns true if an index should be created at the database level for the field.
-
#null? : Bool
Returns a boolean indicating whether the field can be null at the database level.
-
#prepare_save(record, new_record = false)
Runs pre-save logic for the specific field and record at hand.
-
#primary_key? : Bool
Returns a boolean indicating whether the field is a primary key.
-
#related_model
Returns the related model associated with the field.
-
#relation?
Returns true if the field is a relation.
-
#relation_name
Returns the name of the relation on the model associated with the field.
-
#to_column : Management::Column::Base | Nil
Returns a migration column object corresponding to the field at hand.
-
#to_db(value) : ::DB::Any
Converts the field value to the corresponding DB value.
-
#unique? : Bool
Returns a boolean indicating whether the field value should be unique throughout the associated table.
-
#validate(record, value)
Runs custom validation logic for a specific model field and model object.
Constructor Detail
Instance Method Detail
Returns a mandatory non-nil
version of the DB column (and raise otherwise).
Extracts the field value from a DB result set and returns the right object corresponding to this value.
Returns a boolean indicating whether the field can be null at the database level.
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.
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).
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).
Returns a migration column object corresponding to the field at hand.
Returns a boolean indicating whether the field value should be unique throughout the associated table.
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.