module
CQL::ActiveRecord::Relations::BelongsTo
Overview
Enhanced belongs_to association module with improved type safety, error handling, and performance optimizations.
Provides methods to define and manage many-to-one relationships with proper caching, lazy loading, and comprehensive error handling.
Included Modules
Defined in:
active_record/relations/belongs_to.crMacro Summary
-
belongs_to(assoc, klass, foreign_key, optional = true, cache = true)
Define the belongs_to association with enhanced features - param : assoc (Symbol) - Association name - param : klass (Class) - Associated model class - param : foreign_key (Symbol) - Foreign key column name - param : optional (Bool) - Whether association can be nil - param : cache (Bool) - Whether to cache the associated record
Macros inherited from module CQL::ActiveRecord::Relations::BaseRelation
build_query(model_class)
build_query,
destroy_dependent(record, association)
destroy_dependent,
ensure_saved(record)
ensure_saved,
safe_db_operation(&block)
safe_db_operation,
safe_foreign_key(record, key, pk_type)
safe_foreign_key,
safe_id(record, pk_type)
safe_id,
underscore_name(class_name)
underscore_name
Macro Detail
Define the belongs_to association with enhanced features
- param : assoc (Symbol) - Association name
- param : klass (Class) - Associated model class
- param : foreign_key (Symbol) - Foreign key column name
- param : optional (Bool) - Whether association can be nil
- param : cache (Bool) - Whether to cache the associated record
Example
class Comment
include CQL::ActiveRecord::Model(Int64)
db_context AcmeDB, :comments
property user_id : Int64?
belongs_to :user, User, :user_id
end