Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Lightweight::DataMapperOptions Struct Reference

#include <QueryBuilders.hpp>

Public Attributes

bool loadRelations { true }
 Whether to automatically load relations when querying records.
 
size_t eagerLoadDepth { 0 }
 How many levels of relations to eagerly batch-load after a query materializes.
 

Detailed Description

Structural type for options for DataMapper queries. This allows to configure behavior of the queries at compile time when using query builder directly from the DataMapper

Definition at line 25 of file QueryBuilders.hpp.

Member Data Documentation

◆ loadRelations

bool Lightweight::DataMapperOptions::loadRelations { true }

Whether to automatically load relations when querying records.

Definition at line 28 of file QueryBuilders.hpp.

◆ eagerLoadDepth

size_t Lightweight::DataMapperOptions::eagerLoadDepth { 0 }

How many levels of relations to eagerly batch-load after a query materializes.

0 (the default) leaves every relation to load on demand, one query per record touched. A value of N resolves every BelongsTo and HasMany reachable within N levels for the whole result set at once, at a bounded number of queries per relation per level:

// Tracks, their albums, and those albums' artists - a constant number of queries.
auto tracks = dm.Query<Track, DataMapperOptions { .eagerLoadDepth = 2 }>().All();
size_t eagerLoadDepth
How many levels of relations to eagerly batch-load after a query materializes.

Use With<>() instead when only some relations are needed: this option descends into every relation of every record it reaches, which is more queries and more rows than a named path, and instantiates the loader for the whole reachable relation graph. The depth is what bounds that: a cyclic graph (a self-referencing record, or A -> B -> A) terminates because the recursion is cut at a compile-time constant.

HasOneThrough, HasManyThrough and CompositeForeignKey are not batch-loadable and keep their on-demand behaviour.

Definition at line 49 of file QueryBuilders.hpp.


The documentation for this struct was generated from the following file: