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
- CQL::ActiveRecord::Relations::BelongsTo
- CQL::ActiveRecord::Relations::Collection(Target, Pk)
- CQL::ActiveRecord::Relations::HasMany
- CQL::ActiveRecord::Relations::HasOne
- CQL::ActiveRecord::Relations::ManyToMany
Defined in:
active_record/relations/base_relation.crMacro Summary
-
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
-
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. -
ensure_saved(record)
Raises UnsavedRecord unless record has a row; a soft-deleted record keeps its row, so it may be associated
-
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
-
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
-
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
-
underscore_name(class_name)
Generates underscore naming for associations - param : class_name (String) - The class name to convert - return : String - The underscored version
Macro Detail
Creates a query builder with proper error handling
- param : model_class (Class) - The model class to query
- return : CQL::Query - A configured query builder
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.
Raises UnsavedRecord unless record has a row; a soft-deleted record keeps its row, so it may be associated
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
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
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
Generates underscore naming for associations
- param : class_name (String) - The class name to convert
- return : String - The underscored version