module CQL::ActiveRecord::Relations::BaseRelation

Overview

Base module providing common functionality for all relation types This module establishes consistent patterns for error handling, type safety, and shared behaviors across different association types.

Direct including types

Defined in:

active_record/relations/base_relation.cr

Macro Summary

Macro Detail

macro build_query(model_class) #

Creates a query builder with proper error handling

  • param : model_class (Class) - The model class to query
  • return : CQL::Query - A configured query builder

[View source]
macro destroy_dependent(record, association) #

Deletes a dependent record with its delete! and raises RelationError when that returns false (a callback halted it), so the owner's delete rolls back instead of orphaning it. An already soft-deleted record counts as deleted: association loads include it, and its delete! leaves it alone.


[View source]
macro ensure_saved(record) #

Raises UnsavedRecord unless record has a row; a soft-deleted record keeps its row, so it may be associated


[View source]
macro safe_db_operation(&block) #

Safe database operation wrapper with consistent error handling

  • param : operation (Block) - The database operation to execute
  • return : T - The result of the operation
  • raise : RelationError on database errors

[View source]
macro safe_foreign_key(record, key, pk_type) #

Safely retrieves a foreign key value with proper error handling

  • param : record (T) - The record to get foreign key from
  • param : key (Symbol) - The foreign key field name
  • return : Pk - The foreign key value
  • raise : InvalidAssociation if foreign key is nil

[View source]
macro safe_id(record, pk_type) #

Safely retrieves the primary key, raising appropriate error if nil

  • param : record (T) - The record to get ID from
  • return : Pk - The primary key value
  • raise : UnsavedRecord if record has no ID

[View source]
macro underscore_name(class_name) #

Generates underscore naming for associations

  • param : class_name (String) - The class name to convert
  • return : String - The underscored version

[View source]