|
Lightweight 0.20260921.0
|
This API represents a many-to-many relationship between two records through a third record. More...
#include <HasManyThrough.hpp>
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 | |
| ReferencedRecordList const & | All () const noexcept |
| Retrieves the list of loaded records. | |
| ReferencedRecordList & | All () noexcept |
| Retrieves the list of records as mutable reference. | |
| ReferencedRecordList & | Emplace (ReferencedRecordList &&records) noexcept |
| Emplaces the given list of records into this relationship. | |
| std::size_t | Count () const |
| Retrieves the number of records in this relationship. | |
| bool | IsEmpty () const |
| Checks if this relationship is empty. | |
| ReferencedRecord const & | At (std::size_t index) const |
| Retrieves the record at the given index. | |
| ReferencedRecord & | At (std::size_t index) |
| Retrieves the record at the given index. | |
| ReferencedRecord const & | operator[] (std::size_t index) const |
| Retrieves the record at the given index. | |
| ReferencedRecord & | 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. | |
| 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. | |
| void | Reload () |
| Reloads the records from the database. | |
| template<typename Callable > | |
| void | Each (Callable const &callable) |
| Iterates over all records in this relationship. | |
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 66 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 78 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 81 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 90 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::value_type = ReferencedRecord |
Value type for range-based iteration.
Definition at line 93 of file HasManyThrough.hpp.
| using Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::iterator = ReferencedRecordList::iterator |
Iterator type for the list of records.
Definition at line 95 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 97 of file HasManyThrough.hpp.
|
noexcept |
Retrieves the list of loaded records.
Definition at line 232 of file HasManyThrough.hpp.
Referenced by Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, TheOwnerSelector, TheReferencedSelector >::Each().
|
noexcept |
Retrieves the list of records as mutable reference.
Definition at line 241 of file HasManyThrough.hpp.
|
noexcept |
Emplaces the given list of records into this relationship.
Definition at line 253 of file HasManyThrough.hpp.
| std::size_t Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::Count | ( | ) | const |
Retrieves the number of records in this relationship.
Definition at line 261 of file HasManyThrough.hpp.
| bool Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::IsEmpty | ( | ) | const |
Checks if this relationship is empty.
Definition at line 274 of file HasManyThrough.hpp.
References Count.
| HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::ReferencedRecord const & Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::At | ( | std::size_t | index | ) | const |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 281 of file HasManyThrough.hpp.
| HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::ReferencedRecord & Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::At | ( | std::size_t | index | ) |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 288 of file HasManyThrough.hpp.
| HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::ReferencedRecord const & Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::operator[] | ( | std::size_t | index | ) | const |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 295 of file HasManyThrough.hpp.
| HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::ReferencedRecord & Lightweight::HasManyThrough< ReferencedRecordT, ThroughSpec, OwnerSelector, ReferencedSelector >::operator[] | ( | std::size_t | index | ) |
Retrieves the record at the given index.
| index | The index of the record to retrieve. |
Definition at line 302 of file HasManyThrough.hpp.
|
noexcept |
Returns an iterator to the beginning of the record list.
Definition at line 309 of file HasManyThrough.hpp.
|
noexcept |
Returns an iterator to the end of the record list.
Definition at line 316 of file HasManyThrough.hpp.
|
noexcept |
Returns a const iterator to the beginning of the record list.
Definition at line 323 of file HasManyThrough.hpp.
|
noexcept |
Returns a const iterator to the end of the record list.
Definition at line 330 of file HasManyThrough.hpp.
|
inlinenoexcept |
Used internally to configure on-demand loading of the records.
Definition at line 162 of file HasManyThrough.hpp.
|
inline |
Reloads the records from the database.
Definition at line 168 of file HasManyThrough.hpp.
|
inline |
Iterates over all records in this relationship.
| callable | The callable to invoke for each record. |
Definition at line 181 of file HasManyThrough.hpp.
|
staticconstexpr |
Singles out the join record's foreign key pointing at the record owning this relationship.
Definition at line 84 of file HasManyThrough.hpp.
|
staticconstexpr |
Singles out the join record's foreign key pointing at ReferencedRecord.
Definition at line 87 of file HasManyThrough.hpp.