|
Lightweight 0.20261105.1
|
This API represents a many-to-many relationship between two records through a third record. More...
#include <HasManyThrough.hpp>
Classes | |
| struct | Loader |
| Carries the deferred loads, installed by the DataMapper. More... | |
Public Types | |
| using | ThroughRecord = ThroughRecordOf< ThroughSpec > |
| 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 |
| Value type for range-based iteration. | |
| using | iterator = ReferencedRecordList::iterator |
| Iterator type for the list of records. | |
| using | const_iterator = ReferencedRecordList::const_iterator |
| Const iterator type for the list of records. | |
Public Member Functions | |
| RelationResult< std::reference_wrapper< ReferencedRecordList const > > | All () const |
| Retrieves the records, loading them on first access. | |
| RelationResult< std::reference_wrapper< ReferencedRecordList > > | All () |
| Retrieves the records, loading them on first access. | |
| ReferencedRecordList & | Emplace (ReferencedRecordList &&records) noexcept |
| Emplaces the given list of records into this relationship. | |
| RelationResult< std::size_t > | Count () const |
| RelationResult< bool > | IsEmpty () const |
| ReferencedRecord const & | At (std::size_t index) const |
| Retrieves the record at the given index, loading the records on first access. | |
| ReferencedRecord & | At (std::size_t index) |
| Retrieves the record at the given index, loading the records on first access. | |
| ReferencedRecord const & | operator[] (std::size_t index) const |
| Retrieves the record at the given index, loading the records on first access. | |
| ReferencedRecord & | operator[] (std::size_t index) |
| Retrieves the record at the given index, loading the records on first access. | |
| iterator | begin () |
| iterator | end () |
| const_iterator | begin () const |
| const_iterator | end () const |
| std::weak_ordering | operator<=> (HasManyThrough const &other) const noexcept=default |
| Default three-way comparison operator. | |
| void | SetAutoLoader (Loader loader) noexcept |
| Used internally to configure on-demand loading of the records. | |
| RelationResult< void > | Reload () |
| Loads the records from the database again, forgetting what was loaded or known before. | |
| template<typename Callable > | |
| RelationResult< void > | Each (Callable const &callable) |
Calls callable for each record, without holding them all in memory when not loaded yet. | |
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 | ReferencedSelector = TheReferencedSelector |
| Singles out the join record's foreign key pointing at ReferencedRecord. | |
This API represents a many-to-many relationship between two records through a third record.
The join record is named with the Through marker, so that the reader can tell it apart from the referenced record at a glance:
The join record must declare one BelongsTo pointing back at the record owning this relationship, and one pointing at the referenced record. Both are located by matching the relationship type.
When the join record cannot be resolved that way - most notably a self-referential many-to-many, where both of its foreign keys point at the same table - name the two foreign key columns explicitly:
| ReferencedRecordT | The record type on the "many" side of the relationship. |
| ThroughSpec | The join record, wrapped as Through<T>. Naming the record bare is deprecated. |
| TheOwnerSelector | Singles out the join record's foreign key pointing at the owning record. |
| TheReferencedSelector | Singles out the join record's foreign key pointing at ReferencedRecordT. |
Definition at line 69 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::ThroughRecord = ThroughRecordOf<ThroughSpec> |
The record type of the "through" side of the relationship.
Definition at line 81 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::ReferencedRecord = ReferencedRecordT |
The record type of the "many" side of the relationship.
Definition at line 84 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::ReferencedRecordList = std::vector<std::shared_ptr<ReferencedRecord> > |
The list of records on the "many" side of the relationship.
Definition at line 93 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::value_type = ReferencedRecord |
Value type for range-based iteration.
Definition at line 96 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::iterator = ReferencedRecordList::iterator |
Iterator type for the list of records.
Definition at line 98 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::const_iterator = ReferencedRecordList::const_iterator |
Const iterator type for the list of records.
Definition at line 100 of file HasManyThrough.hpp.
|
inline |
Retrieves the records, loading them on first access.
Never throws for unavailable records: the reason comes back as the error instead.
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 110 of file HasManyThrough.hpp.
Referenced by Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::Each().
|
inline |
Retrieves the records, loading them on first access.
Never throws for unavailable records: the reason comes back as the error instead.
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 116 of file HasManyThrough.hpp.
|
inlinenoexcept |
Emplaces the given list of records into this relationship.
Definition at line 122 of file HasManyThrough.hpp.
|
inline |
Definition at line 132 of file HasManyThrough.hpp.
References Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::Loader::count, NotConfigured, and QueryFailed.
Referenced by Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::IsEmpty().
|
inline |
Definition at line 152 of file HasManyThrough.hpp.
|
inline |
Retrieves the record at the given index, loading the records on first access.
| index | The index of the record to retrieve. |
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
| std::out_of_range | index is out of bounds. |
Definition at line 162 of file HasManyThrough.hpp.
|
inline |
Retrieves the record at the given index, loading the records on first access.
| index | The index of the record to retrieve. |
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
| std::out_of_range | index is out of bounds. |
Definition at line 168 of file HasManyThrough.hpp.
|
inline |
Retrieves the record at the given index, loading the records on first access.
| index | The index of the record to retrieve; out of bounds is undefined behaviour. |
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
Definition at line 177 of file HasManyThrough.hpp.
|
inline |
Retrieves the record at the given index, loading the records on first access.
| index | The index of the record to retrieve; out of bounds is undefined behaviour. |
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
Definition at line 183 of file HasManyThrough.hpp.
|
inline |
Returns an iterator to the beginning of the record list, loading the records on first access.
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
Definition at line 190 of file HasManyThrough.hpp.
|
inline |
Returns an iterator to the end of the record list, loading the records on first access.
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
Definition at line 197 of file HasManyThrough.hpp.
|
inline |
Returns a const iterator to the beginning of the record list, loading the records on first access.
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
Definition at line 204 of file HasManyThrough.hpp.
|
inline |
Returns a const iterator to the end of the record list, loading the records on first access.
| SqlRequireLoadedError | The records are unavailable; All() reports why without throwing. |
Definition at line 211 of file HasManyThrough.hpp.
|
inlinenoexcept |
Used internally to configure on-demand loading of the records.
Definition at line 231 of file HasManyThrough.hpp.
|
inline |
Loads the records from the database again, forgetting what was loaded or known before.
Definition at line 238 of file HasManyThrough.hpp.
|
inline |
Calls callable for each record, without holding them all in memory when not loaded yet.
An exception thrown by callable propagates unchanged.
| callable | Called once per record. |
Definition at line 253 of file HasManyThrough.hpp.
References Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::All(), Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::Loader::each, and QueryFailed.
|
staticconstexpr |
Singles out the join record's foreign key pointing at the record owning this relationship.
Definition at line 87 of file HasManyThrough.hpp.
|
staticconstexpr |
Singles out the join record's foreign key pointing at ReferencedRecord.
Definition at line 90 of file HasManyThrough.hpp.