|
Lightweight 0.20260625.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 noexcept |
| Retrieves the list of loaded records. | |
| ReferencedRecordList & | All () noexcept |
| 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. | |
| 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 () noexcept |
| Returns an iterator to the beginning of the record list. | |
| iterator | end () noexcept |
| Returns an iterator to the end of the record list. | |
| const_iterator | begin () const noexcept |
| Returns a const iterator to the beginning of the record list. | |
| const_iterator | end () const noexcept |
| Returns a const iterator to the end of the record list. | |
| 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 63 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::ReferencedRecord = OtherRecord |
The record type of the "many" side of the relationship.
Definition at line 71 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 77 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::value_type = OtherRecord |
Record type of the "many" side of the relationship.
Definition at line 80 of file HasMany.hpp.
| using Lightweight::HasMany< OtherRecord, TheInverseSelector >::iterator = ReferencedRecordList::iterator |
Iterator type for the list of records.
Definition at line 83 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 86 of file HasMany.hpp.
|
inlinenoexcept |
Retrieves the list of loaded records.
Definition at line 242 of file HasMany.hpp.
|
inlinenoexcept |
Retrieves the list of records as mutable reference.
Definition at line 219 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 227 of file HasMany.hpp.
|
inlinenoexcept |
Emplaces the given list of records.
Definition at line 210 of file HasMany.hpp.
|
inlinenoexcept |
Retrieves the number of records in this 1-to-many relationship.
Definition at line 249 of file HasMany.hpp.
|
inlinenoexcept |
Checks if this 1-to-many relationship is empty.
Definition at line 261 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 267 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 274 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 281 of file HasMany.hpp.
|
inline |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 288 of file HasMany.hpp.
|
inlinenoexcept |
Returns an iterator to the beginning of the record list.
Definition at line 296 of file HasMany.hpp.
Referenced by Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
|
inlinenoexcept |
Returns an iterator to the end of the record list.
Definition at line 307 of file HasMany.hpp.
Referenced by Lightweight::HasMany< OtherRecord, TheInverseSelector >::end().
|
inlinenoexcept |
Returns a const iterator to the beginning of the record list.
Definition at line 318 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::begin().
|
inlinenoexcept |
Returns a const iterator to the end of the record list.
Definition at line 330 of file HasMany.hpp.
References Lightweight::HasMany< OtherRecord, TheInverseSelector >::end().
|
inlinenoexcept |
Used internally to configure on-demand loading of the records.
Definition at line 195 of file HasMany.hpp.
Referenced by Lightweight::DataMapper::ConfigureRelationAutoLoading().
|
staticconstexpr |
Singles out the foreign key of OtherRecord that backs this relationship.
Definition at line 74 of file HasMany.hpp.