Lightweight 0.20250904.0
Loading...
Searching...
No Matches
Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT > Class Template Reference

This API represents a many-to-many relationship between two records through a third record. More...

#include <HasManyThrough.hpp>

Public Types

using ThroughRecord = ThroughRecordT
 The record type of the "through" side of the relationship.
 
using ReferencedRecord = ReferencedRecordT
 The record type of the "many" side of the relationship.
 
using ReferencedRecordList = std::vector< std::shared_ptr< ReferencedRecord > >
 The list of records on the "many" side of the relationship.
 
using value_type = ReferencedRecord
 
using iterator = typename ReferencedRecordList::iterator
 
using const_iterator = typename ReferencedRecordList::const_iterator
 

Public Member Functions

ReferencedRecordList const & All () const noexcept
 Retrieves the list of loaded records.
 
ReferencedRecordListAll () noexcept
 Retrieves the list of records as mutable reference.
 
ReferencedRecordListEmplace (ReferencedRecordList &&records) noexcept
 Emplaces the given list of records into this relationship.
 
std::size_t Count () const
 Retrieves the number of records in this relationship.
 
std::size_t IsEmpty () const
 Checks if this relationship is empty.
 
ReferencedRecord const & At (std::size_t index) const
 Retrieves the record at the given index.
 
ReferencedRecordAt (std::size_t index)
 Retrieves the record at the given index.
 
ReferencedRecord const & operator[] (std::size_t index) const
 Retrieves the record at the given index.
 
ReferencedRecordoperator[] (std::size_t index)
 Retrieves the record at the given index.
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
std::weak_ordering operator<=> (HasManyThrough const &other) const noexcept=default
 
void SetAutoLoader (Loader loader) noexcept
 Used internally to configure on-demand loading of the records.
 
void Reload ()
 Reloads the records from the database.
 
template<typename Callable >
void Each (Callable const &callable)
 Iterates over all records in this relationship.
 

Detailed Description

template<typename ReferencedRecordT, typename ThroughRecordT>
class Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >

This API represents a many-to-many relationship between two records through a third record.

See also
DataMapper, Field, HasMany

Definition at line 23 of file HasManyThrough.hpp.

Member Typedef Documentation

◆ ThroughRecord

template<typename ReferencedRecordT , typename ThroughRecordT >
using Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::ThroughRecord = ThroughRecordT

The record type of the "through" side of the relationship.

Definition at line 27 of file HasManyThrough.hpp.

◆ ReferencedRecord

template<typename ReferencedRecordT , typename ThroughRecordT >
using Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecord = ReferencedRecordT

The record type of the "many" side of the relationship.

Definition at line 30 of file HasManyThrough.hpp.

◆ ReferencedRecordList

template<typename ReferencedRecordT , typename ThroughRecordT >
using Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecordList = std::vector<std::shared_ptr<ReferencedRecord> >

The list of records on the "many" side of the relationship.

Definition at line 33 of file HasManyThrough.hpp.

◆ value_type

template<typename ReferencedRecordT , typename ThroughRecordT >
using Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::value_type = ReferencedRecord

Definition at line 35 of file HasManyThrough.hpp.

◆ iterator

template<typename ReferencedRecordT , typename ThroughRecordT >
using Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::iterator = typename ReferencedRecordList::iterator

Definition at line 36 of file HasManyThrough.hpp.

◆ const_iterator

template<typename ReferencedRecordT , typename ThroughRecordT >
using Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::const_iterator = typename ReferencedRecordList::const_iterator

Definition at line 37 of file HasManyThrough.hpp.

Member Function Documentation

◆ All() [1/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecordList const & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::All ( ) const
noexcept

Retrieves the list of loaded records.

Definition at line 152 of file HasManyThrough.hpp.

Referenced by Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::Each().

◆ All() [2/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecordList & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::All ( )
noexcept

Retrieves the list of records as mutable reference.

Definition at line 162 of file HasManyThrough.hpp.

◆ Emplace()

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecordList & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::Emplace ( ReferencedRecordList &&  records)
noexcept

Emplaces the given list of records into this relationship.

Definition at line 170 of file HasManyThrough.hpp.

◆ Count()

template<typename ReferencedRecordT , typename ThroughRecordT >
std::size_t Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::Count ( ) const

Retrieves the number of records in this relationship.

Definition at line 179 of file HasManyThrough.hpp.

◆ IsEmpty()

template<typename ReferencedRecordT , typename ThroughRecordT >
std::size_t Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::IsEmpty ( ) const

Checks if this relationship is empty.

Definition at line 191 of file HasManyThrough.hpp.

◆ At() [1/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecord const & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::At ( std::size_t  index) const

Retrieves the record at the given index.

Parameters
indexThe index of the record to retrieve.
Note
This method will on-demand load the records if they are not already loaded.
This method will throw if the index is out of bounds.

Definition at line 199 of file HasManyThrough.hpp.

◆ At() [2/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecord & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::At ( std::size_t  index)

Retrieves the record at the given index.

Parameters
indexThe index of the record to retrieve.
Note
This method will on-demand load the records if they are not already loaded.
This method will throw if the index is out of bounds.

Definition at line 205 of file HasManyThrough.hpp.

◆ operator[]() [1/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecord const & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::operator[] ( std::size_t  index) const

Retrieves the record at the given index.

Parameters
indexThe index of the record to retrieve.
Note
This method will on-demand load the records if they are not already loaded.
This method will NOT throw if the index is out of bounds. The behaviour is undefined.

Definition at line 214 of file HasManyThrough.hpp.

◆ operator[]() [2/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::ReferencedRecord & Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::operator[] ( std::size_t  index)

Retrieves the record at the given index.

Parameters
indexThe index of the record to retrieve.
Note
This method will on-demand load the records if they are not already loaded.
This method will NOT throw if the index is out of bounds. The behaviour is undefined.

Definition at line 220 of file HasManyThrough.hpp.

◆ begin() [1/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::iterator Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::begin ( )
noexcept

Definition at line 228 of file HasManyThrough.hpp.

◆ end() [1/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::iterator Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::end ( )
noexcept

Definition at line 234 of file HasManyThrough.hpp.

◆ begin() [2/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::const_iterator Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::begin ( ) const
noexcept

Definition at line 240 of file HasManyThrough.hpp.

◆ end() [2/2]

template<typename ReferencedRecordT , typename ThroughRecordT >
HasManyThrough< ReferencedRecordT, ThroughRecordT >::const_iterator Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::end ( ) const
noexcept

Definition at line 247 of file HasManyThrough.hpp.

◆ SetAutoLoader()

template<typename ReferencedRecordT , typename ThroughRecordT >
void Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::SetAutoLoader ( Loader  loader)
inlinenoexcept

Used internally to configure on-demand loading of the records.

Definition at line 97 of file HasManyThrough.hpp.

Referenced by Lightweight::DataMapper::ConfigureRelationAutoLoading().

◆ Reload()

template<typename ReferencedRecordT , typename ThroughRecordT >
void Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::Reload ( )
inline

Reloads the records from the database.

Definition at line 103 of file HasManyThrough.hpp.

◆ Each()

template<typename ReferencedRecordT , typename ThroughRecordT >
template<typename Callable >
void Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::Each ( Callable const &  callable)
inline

Iterates over all records in this relationship.

Parameters
callableThe callable to invoke for each record.
Note
This method will on-demand load the records if they are not already loaded, but not hold them all in memory.

Definition at line 116 of file HasManyThrough.hpp.

References Lightweight::HasManyThrough< ReferencedRecordT, ThroughRecordT >::All().


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