class

DBX::ORM::Schema

Inherits DBX::ORM::SchemaInjectFields / DBX::ORM::SchemaInjectForFinal / DBX::ORM::SchemaField / DBX::ORM::SchemaRelation / JSON::Serializable::Unmapped / JSON::Serializable / DB::Mappable / DB::Serializable / Reference / Object

Model Schema.

Constants

FIELDS = {} of String => HashLiteral(String, ASTNode)
RELATIONS = {} of String => ASTNode

Constructors

new(rs : DB::ResultSet)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Class methods

fields

Returns all SQL fields definitions.

Source
from_rs(rs : DB::ResultSet)
Source
sql_fields

Returns the SQL fields of the model separated by a comma (table.column, ...).

Source
sql_rel_fields

Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).

Source

Instance methods

_pk

Same as _pk but may return nil when the record hasn't been saved instead of raising.

Source
_pk!

Always returns this record's primary key value, even when the primary key isn't named _pk.

Source
_ukey

Unique (virtual) key used to compare the uniqueness of models. By default this method returns the primary key (_pk) value.

This method avoid to rely directly on the primary key in case there is none in the structure of the SQL table (even if there should always be one). Used in the relation algorithm. Also, can be useful when there is a need to check the uniqueness in other cases.

If for some reason your model does not have a primary key, you can override this method to return a unique result related to the fields in your table, for example:

@[DB::Field(ignore: true)]
@[JSON::Field(ignore: true)]
def _ukey
  "#{self.group_id}.#{self.user_id}"
end
Source

Nested types