|
Lightweight 0.20261105.1
|
This HasMany<OtherRecord> represents a simple one-to-many relationship between two records. More...
#include <HasMany.hpp>
Classes | |
| struct | Loader |
| Carries the deferred loads, installed by the DataMapper. More... | |
Public Types | |
| using | ReferencedRecord = OtherRecord |
| The record type of the "many" side of the relationship. | |
| using | ReferencedRecordList = std::vector< std::shared_ptr< OtherRecord > > |
| The list of records on the "many" side of the relationship. | |
| using | value_type = OtherRecord |
| Record type of the "many" side of the relationship. | |
| 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. | |
| template<typename Callable > | |
| RelationResult< void > | Each (Callable const &callable) |
Calls callable for each record, without holding them all in memory when not loaded yet. | |
| ReferencedRecordList & | Emplace (ReferencedRecordList &&records) noexcept |
| Emplaces the given list of records. | |
| ReferencedRecordList * | LoadedRecords () noexcept |
Returns the already-loaded records, or nullptr when the relation is not loaded. | |
| RelationResult< std::size_t > | Count () const |
| RelationResult< bool > | IsEmpty () const |
| OtherRecord const & | At (std::size_t index) const |
| Retrieves the record at the given index, loading the records on first access. | |
| OtherRecord & | At (std::size_t index) |
| Retrieves the record at the given index, loading the records on first access. | |
| OtherRecord const & | operator[] (std::size_t index) const |
| Retrieves the record at the given index, loading the records on first access. | |
| OtherRecord & | 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 |
| constexpr std::weak_ordering | operator<=> (HasMany const &other) const noexcept=default |
| Three-way comparison operator. | |
| constexpr bool | operator== (HasMany const &other) const noexcept=default |
| Equality comparison operator. | |
| constexpr bool | operator!= (HasMany const &other) const noexcept=default |
| Inequality comparison operator. | |
| void | SetAutoLoader (Loader loader) noexcept |
| Used internally to configure on-demand loading of the records. | |
Static Public Attributes | |
| static constexpr auto | InverseSelector = TheInverseSelector |
Singles out the foreign key of OtherRecord that backs this relationship. | |
This HasMany<OtherRecord> represents a simple one-to-many relationship between two records.
The HasMany<OtherRecord> is a member of the "one" side of the relationship.
OtherRecord must declare a BelongsTo member that points back to this "one" side. That member is located by matching the relationship type, not by its position in either record, so the two relationship members may be declared at any index. Declaring no such BelongsTo is a compile-time error.
When OtherRecord holds more than one foreign key into this record's table - say a meeting that references the same person table both as its organizer and as whoever writes the minutes - the inverse is ambiguous. Name the foreign key column through TheInverseSelector to single one out:
A meeting with many attendees is a many-to-many instead - see HasManyThrough. The worked example in docs/sql-to-lightweight.md combines both shapes.
| OtherRecord | The record type on the "many" side of the relationship. |
| TheInverseSelector | Singles out one of several foreign keys, see the RelationSelector concept. |
Definition at line 66 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::ReferencedRecord = OtherRecord |
The record type of the "many" side of the relationship.
Definition at line 74 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::ReferencedRecordList = std::vector<std::shared_ptr<OtherRecord> > |
The list of records on the "many" side of the relationship.
Definition at line 80 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::value_type = OtherRecord |
Record type of the "many" side of the relationship.
Definition at line 83 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::iterator = ReferencedRecordList::iterator |
Iterator type for the list of records.
Definition at line 86 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::const_iterator = ReferencedRecordList::const_iterator |
Const iterator type for the list of records.
Definition at line 89 of file HasMany.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 285 of file HasMany.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 278 of file HasMany.hpp.
| RelationResult< void > Lightweight::HasMany< OtherRecord, InverseSelector >::Each | ( | Callable const & | callable | ) |
Calls callable for each record, without holding them all in memory when not loaded yet.
Use this to iterate over all records when the full data set would be too large to keep. An exception thrown by callable propagates unchanged.
| callable | Called once per record. |
Definition at line 293 of file HasMany.hpp.
References QueryFailed.
|
inlinenoexcept |
Emplaces the given list of records.
Definition at line 270 of file HasMany.hpp.
|
inlinenoexcept |
Returns the already-loaded records, or nullptr when the relation is not loaded.
Unlike All(), this never runs the on-demand loader: it reports what is present right now, which is what lets the batched relation loading walk one level deeper (With<A, B>()).
nullptr if the relation was never loaded. Definition at line 123 of file HasMany.hpp.
|
inline |
Definition at line 310 of file HasMany.hpp.
References NotConfigured, and QueryFailed.
|
inline |
Definition at line 330 of file HasMany.hpp.
References Count.
|
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 336 of file HasMany.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 342 of file HasMany.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 348 of file HasMany.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 354 of file HasMany.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 361 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
Referenced by Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin(), and Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
|
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 367 of file HasMany.hpp.
Referenced by Lightweight::HasMany< OtherRecord, TheInverseSelector >::end().
|
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 374 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
|
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 381 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::end().
|
inlinenoexcept |
Used internally to configure on-demand loading of the records.
Definition at line 228 of file HasMany.hpp.
Referenced by Lightweight::DataMapper::ConfigureRelationAutoLoading().
|
staticconstexpr |
Singles out the foreign key of OtherRecord that backs this relationship.
Definition at line 77 of file HasMany.hpp.