class DBX::ORM::Schema
- DBX::ORM::Schema
- Reference
- Object
Overview
Model
Schema.
Included Modules
- DB::Mappable
- DB::Serializable
- DBX::ORM::SchemaInjectFields
- DBX::ORM::SchemaInjectForFinal
- JSON::Serializable
- JSON::Serializable::Unmapped
Defined in:
orm/schema/schema.crConstant Summary
-
FIELDS =
{} of String => HashLiteral(String, ASTNode)
-
RELATIONS =
{} of String => ASTNode
Constructors
Class Method Summary
-
.fields : MetaFieldHash
Returns all SQL fields definitions.
- .from_rs(rs : DB::ResultSet)
-
.sql_fields : String
Returns the SQL fields of the model separated by a comma (table.column, ...).
-
.sql_rel_fields : String
Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).
Instance Method Summary
-
#_pk
Same as
#_pk
but may returnnil
when the record hasn't been saved instead of raising. -
#_pk!
Always returns this record's primary key value, even when the primary key isn't named
#_pk
. -
#_ukey
Unique (virtual) key used to compare the uniqueness of models.
Constructor Detail
Class Method Detail
Returns the SQL fields of the model separated by a comma (table.column, ...).
Returns the SQL fields of the model (for the relations) separated by a comma (table.column, ...).
Instance Method Detail
Always returns this record's primary key value, even when the primary key
isn't named #_pk
.
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