Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector > Class Template Reference

Represents a one-to-one relationship through a join table. More...

#include <HasOneThrough.hpp>

Classes

struct  Loader
 Carries the deferred load, installed by the DataMapper. More...
 

Public Types

using ThroughRecord = ThroughRecordOf< ThroughSpec >
 The record type of the "through" side of the relationship.
 
using ReferencedRecord = OtherTable
 The record type of the "Other" side of the relationship.
 

Public Member Functions

LIGHTWEIGHT_FORCE_INLINE constexpr void EmplaceRecord (std::shared_ptr< ReferencedRecord > record)
 Emplaces the given record into this relationship.
 
LIGHTWEIGHT_FORCE_INLINE RelationResult< std::reference_wrapper< ReferencedRecord > > Record ()
 Retrieves the record in this relationship, loading it on first access.
 
LIGHTWEIGHT_FORCE_INLINE RelationResult< std::reference_wrapper< ReferencedRecord const > > Record () const
 Retrieves the record in this relationship, loading it on first access.
 
LIGHTWEIGHT_FORCE_INLINE constexpr bool IsLoaded () const noexcept
 Checks if the record is loaded.
 
LIGHTWEIGHT_FORCE_INLINE void Unload () noexcept
 Unloads the record from memory, so the next access loads it again.
 
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord & operator* ()
 Retrieves the record in this relationship, loading it on first access.
 
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord const & operator* () const
 Retrieves the record in this relationship, loading it on first access.
 
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord * operator-> ()
 Retrieves the record in this relationship, loading it on first access.
 
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord const * operator-> () const
 Retrieves the record in this relationship, loading it on first access.
 
std::weak_ordering operator<=> (HasOneThrough const &other) const noexcept=default
 Default three-way comparison operator.
 
void SetAutoLoader (Loader loader)
 Used internally to configure on-demand loading of the record.
 

Static Public Attributes

static constexpr auto OwnerSelector = TheOwnerSelector
 Singles out the join record's foreign key pointing at the record owning this relationship.
 
static constexpr auto ThroughSelector = TheThroughSelector
 Singles out ReferencedRecord's foreign key pointing at ThroughRecord.
 

Detailed Description

template<typename OtherTable, typename ThroughSpec, auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
class Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >

Represents a one-to-one relationship through a join table.

The OtherTable parameter is the record reached through the join table. The ThroughSpec parameter is the join table, which references the current record. It is named with the Through marker, so that the reader can tell it apart from the referenced record:

struct Account;
struct AccountHistory;
struct Supplier
{
};
Represents a one-to-one relationship through a join table.
Represents a single column in a table.
Definition Field.hpp:154

Both foreign keys are located by matching the relationship type. When either record holds more than one foreign key into the same table, name the column to single one out - see the RelationSelector concept and the example on HasManyThrough.

Template Parameters
OtherTableThe record type reached through the join table.
ThroughSpecThe join record, wrapped as Through<T>. Naming the record bare is deprecated.
TheOwnerSelectorSingles out the join record's foreign key pointing at the owning record.
TheThroughSelectorSingles out OtherTable's foreign key pointing at the join record.
See also
DataMapper, Field, HasManyThrough, Through, RelationSelector

Definition at line 50 of file HasOneThrough.hpp.

Member Typedef Documentation

◆ ThroughRecord

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
using Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::ThroughRecord = ThroughRecordOf<ThroughSpec>

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

Definition at line 62 of file HasOneThrough.hpp.

◆ ReferencedRecord

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
using Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::ReferencedRecord = OtherTable

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

Definition at line 65 of file HasOneThrough.hpp.

Member Function Documentation

◆ EmplaceRecord()

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE constexpr void Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::EmplaceRecord ( std::shared_ptr< ReferencedRecord >  record)
inlineconstexpr

Emplaces the given record into this relationship.

Definition at line 74 of file HasOneThrough.hpp.

◆ Record() [1/2]

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE RelationResult< std::reference_wrapper< ReferencedRecord > > Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::Record ( )
inline

Retrieves the record in this relationship, loading it on first access.

Never throws for an unavailable record: the reason comes back as the error instead.

Returns
The record; or RelationError::NotFound when there is none, RelationError::NotConfigured when there is no loader (a hand-built record, or one read with loadRelations = false), RelationError::Outdated when the default connection string changed since the record was read, RelationError::QueryFailed when the load query failed.

Definition at line 89 of file HasOneThrough.hpp.

◆ Record() [2/2]

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE RelationResult< std::reference_wrapper< ReferencedRecord const > > Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::Record ( ) const
inline

Retrieves the record in this relationship, loading it on first access.

Never throws for an unavailable record: the reason comes back as the error instead.

Returns
The record; or RelationError::NotFound when there is none, RelationError::NotConfigured when there is no loader (a hand-built record, or one read with loadRelations = false), RelationError::Outdated when the default connection string changed since the record was read, RelationError::QueryFailed when the load query failed.

Definition at line 95 of file HasOneThrough.hpp.

◆ IsLoaded()

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE constexpr bool Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::IsLoaded ( ) const
inlineconstexprnoexcept

Checks if the record is loaded.

Definition at line 101 of file HasOneThrough.hpp.

◆ Unload()

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE void Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::Unload ( )
inlinenoexcept

Unloads the record from memory, so the next access loads it again.

Definition at line 107 of file HasOneThrough.hpp.

◆ operator*() [1/2]

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord & Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::operator* ( )
inline

Retrieves the record in this relationship, loading it on first access.

Exceptions
SqlRequireLoadedErrorThe record is unavailable; Record() reports why without throwing.

Definition at line 115 of file HasOneThrough.hpp.

◆ operator*() [2/2]

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord const & Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::operator* ( ) const
inline

Retrieves the record in this relationship, loading it on first access.

Exceptions
SqlRequireLoadedErrorThe record is unavailable; Record() reports why without throwing.

Definition at line 122 of file HasOneThrough.hpp.

◆ operator->() [1/2]

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord * Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::operator-> ( )
inline

Retrieves the record in this relationship, loading it on first access.

Exceptions
SqlRequireLoadedErrorThe record is unavailable; Record() reports why without throwing.

Definition at line 130 of file HasOneThrough.hpp.

◆ operator->() [2/2]

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
LIGHTWEIGHT_FORCE_INLINE ReferencedRecord const * Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::operator-> ( ) const
inline

Retrieves the record in this relationship, loading it on first access.

Exceptions
SqlRequireLoadedErrorThe record is unavailable; Record() reports why without throwing.

Definition at line 137 of file HasOneThrough.hpp.

◆ SetAutoLoader()

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
void Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::SetAutoLoader ( Loader  loader)
inline

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

Definition at line 154 of file HasOneThrough.hpp.

Member Data Documentation

◆ OwnerSelector

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
constexpr auto Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::OwnerSelector = TheOwnerSelector
staticconstexpr

Singles out the join record's foreign key pointing at the record owning this relationship.

Definition at line 68 of file HasOneThrough.hpp.

◆ ThroughSelector

template<typename OtherTable , typename ThroughSpec , auto TheOwnerSelector = AutoDetectRelation, auto TheThroughSelector = AutoDetectRelation>
constexpr auto Lightweight::HasOneThrough< OtherTable, ThroughSpec, TheOwnerSelector, TheThroughSelector >::ThroughSelector = TheThroughSelector
staticconstexpr

Singles out ReferencedRecord's foreign key pointing at ThroughRecord.

Definition at line 71 of file HasOneThrough.hpp.


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