Expand description
Eager loading utilities for avoiding N+1 query problems
Provides batch loading of related entities to avoid the N+1 query problem.
§Example
ⓘ
use ferro_rs::database::BatchLoad;
// Load animals with their shelter in 2 queries instead of N+1
let animals = Animal::query().all().await?;
let shelters = Shelter::batch_load(animals.iter().map(|a| a.shelter_id)).await?;
// Access related data
for animal in &animals {
if let Some(shelter) = shelters.get(&animal.shelter_id) {
println!("{} is at {}", animal.name, shelter.name);
}
}Macros§
- impl_
batch_ load - Macro to implement BatchLoad for an entity with a primary key
- impl_
batch_ load_ many - Macro to implement BatchLoadMany for has_many relationships
Traits§
- Batch
Load - Trait for batch loading entities by their primary key
- Batch
Load Many - Trait for loading has_many relationships in batch
Functions§
- batch_
load_ by_ id - Helper function to batch load entities by primary key
- batch_
load_ has_ many - Helper function to batch load has_many relations