Skip to main content

Module relations

Module relations 

Source
Expand description

Relationship management for ORM entities

This module provides traits and utilities for defining and loading relationships between entities, preventing N+1 queries through automatic batching and eager loading.

§Example

use ormkit::relations::{BelongsTo, HasMany, RelationBuilder};

// Define relationship
impl BelongsTo<User> for Post {
    fn foreign_key() -> &'static str {
        "user_id"
    }
}

// Load relationship
let posts_with_users = RelationBuilder::for_entities(posts)
    .load::<User>(&pool)
    .await?;

Structs§

BatchLoader
Batch loading helper to prevent N+1 queries
HasManyLoader
Loader for multiple related entities (HasMany relationship)
Loaded
Wrapper for entities with loaded relationships
RelationBuilder
Builder for loading relationships on entities
RelationLoader
Loader for a single related entity (BelongsTo relationship)
RelationMeta
Metadata about a relationship

Enums§

LoadError
Errors that can occur during relationship loading
LoadStrategy
Loading strategy for relationships
LoaderError
Errors that can occur during lazy loading

Traits§

BelongsTo
Trait for BelongsTo relationships (child-to-parent)
ForeignKeyExtractor
Helper to extract foreign key values from entities
HasMany
Trait for HasMany relationships (parent-to-children)