|
Lightweight 0.20260921.0
|
This HasMany<OtherRecord> represents a simple one-to-many relationship between two records. More...
#include <HasMany.hpp>
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 | |
| ReferencedRecordList const & | All () const |
| Retrieves the list of loaded records. | |
| ReferencedRecordList & | All () |
| Retrieves the list of records as mutable reference. | |
| template<typename Callable > | |
| void | Each (Callable const &callable) |
| Iterates over the list of records and calls the given callable for each record. | |
| 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. | |
| std::size_t | Count () const noexcept |
| Retrieves the number of records in this 1-to-many relationship. | |
| bool | IsEmpty () const noexcept |
| Checks if this 1-to-many relationship is empty. | |
| OtherRecord const & | At (std::size_t index) const |
| Retrieves the record at the given index. | |
| OtherRecord & | At (std::size_t index) |
| Retrieves the record at the given index. | |
| OtherRecord const & | operator[] (std::size_t index) const |
| Retrieves the record at the given index. | |
| OtherRecord & | operator[] (std::size_t index) |
| Retrieves the record at the given index. | |
| 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 64 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::ReferencedRecord = OtherRecord |
The record type of the "many" side of the relationship.
Definition at line 72 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 78 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::value_type = OtherRecord |
Record type of the "many" side of the relationship.
Definition at line 81 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::iterator = ReferencedRecordList::iterator |
Iterator type for the list of records.
Definition at line 84 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 87 of file HasMany.hpp.
|
inline |
Retrieves the list of loaded records.
Definition at line 275 of file HasMany.hpp.
|
inline |
Retrieves the list of records as mutable reference.
Definition at line 252 of file HasMany.hpp.
| void Lightweight::HasMany< OtherRecord, InverseSelector >::Each | ( | Callable const & | callable | ) |
Iterates over the list of records and calls the given callable for each record.
Definition at line 260 of file HasMany.hpp.
|
inlinenoexcept |
Emplaces the given list of records.
Definition at line 244 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 119 of file HasMany.hpp.
|
inlinenoexcept |
Retrieves the number of records in this 1-to-many relationship.
Definition at line 282 of file HasMany.hpp.
|
inlinenoexcept |
Checks if this 1-to-many relationship is empty.
Definition at line 294 of file HasMany.hpp.
References Count.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 300 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 307 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 314 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 321 of file HasMany.hpp.
|
inline |
Returns an iterator to the beginning of the record list.
Definition at line 329 of file HasMany.hpp.
Referenced by Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
|
inline |
Returns an iterator to the end of the record list.
Definition at line 336 of file HasMany.hpp.
Referenced by Lightweight::HasMany< OtherRecord, TheInverseSelector >::end().
|
inline |
Returns a const iterator to the beginning of the record list.
Definition at line 344 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
|
inline |
Returns a const iterator to the end of the record list.
Definition at line 352 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::end().
|
inlinenoexcept |
Used internally to configure on-demand loading of the records.
Definition at line 219 of file HasMany.hpp.
Referenced by Lightweight::DataMapper::ConfigureRelationAutoLoading().
|
staticconstexpr |
Singles out the foreign key of OtherRecord that backs this relationship.
Definition at line 75 of file HasMany.hpp.