class DBX::ORM::Schema

Overview

Model Schema.

Included Modules

Defined in:

orm/schema/schema.cr

Constant Summary

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

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(rs : DB::ResultSet) #

[View source]
def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.fields : MetaFieldHash #

Returns all SQL fields definitions.


[View source]
def self.from_rs(rs : DB::ResultSet) #

[View source]
def self.sql_fields : String #

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


[View source]
def self.sql_rel_fields : String #

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


[View source]

Instance Method Detail

def _pk #

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


[View source]
def _pk! #

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


[View source]
def _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

[View source]