module CQL::ActiveRecord::Model(Pk)

Overview

The Model module provides Active Record functionality for your models. It combines validations, callbacks, persistence, and relationship handling following SOLID principles.

Example Using the Model module

class Article
  include CQL::ActiveRecord::Model(Int64)
  db_context AcmeDB, :posts

  property title : String = ""
  property body : String?
  property user_id : Int64 = 0_i64
  property published : Bool = false

  validate :title, presence: true, size: 3..100

  before_validation :strip_title

  belongs_to :user, User, :user_id

  def initialize(@title : String = "", @user_id : Int64 = 0_i64)
  end

  private def strip_title
    @title = @title.strip
  end
end

Defined in:

active_record/model.cr