module CQL::ActiveRecord::Callbacks

Overview

The Callbacks module provides lifecycle hooks for Active Record models. It allows you to execute code at specific points in the model's lifecycle, similar to Rails ActiveRecord callbacks.

Features:

Example Using the Callbacks module

class Member
  include CQL::ActiveRecord::Model(Int64)
  db_context AcmeDB, :users

  property name : String = ""
  property email : String = ""

  before_validation :normalize_email
  after_create :send_welcome_email

  def initialize(@name : String = "", @email : String = "")
  end

  private def normalize_email
    @email = @email.downcase.strip # any value but false continues the chain
  end

  private def send_welcome_email
    puts "Welcome, #{@email}"
  end
end

Defined in:

active_record/callbacks.cr