|
Lightweight 0.20260625.0
|
Represents a one-to-one relationship. More...
#include <BelongsTo.hpp>
Public Types | |
| using | ReferencedRecord = MemberClassType< decltype(TheReferencedField)> |
| Represents the record type of the other field. | |
| using | BaseType = std::remove_cvref_t< decltype(std::declval< ReferencedRecord >().*ReferencedField)>::ValueType |
| Represents the base column type of the foreign key, matching the primary key of the other record. | |
| using | ValueType = std::conditional_t< Nullable==SqlNullable::Null, std::optional< BaseType >, BaseType > |
Public Member Functions | |
| template<typename... S> requires std::constructible_from<ValueType, S...> | |
| constexpr | BelongsTo (S &&... value) noexcept |
| Constructs a new BelongsTo with the given value(s) forwarded to the underlying value type. | |
| constexpr | BelongsTo (ReferencedRecord const &other) noexcept |
| Constructs a new BelongsTo from the given referenced record, copying its primary key. | |
| constexpr | BelongsTo (BelongsTo const &other) noexcept |
| Copy constructor. | |
| constexpr | BelongsTo (BelongsTo &&other) noexcept |
| Move constructor. | |
| BelongsTo & | operator= (SqlNullType) noexcept |
| Assigns NULL to the relationship, clearing the loaded record. | |
| BelongsTo & | operator= (ReferencedRecord &other) |
| Assigns a referenced record, updating the foreign key and loaded state. | |
| BelongsTo & | operator= (BelongsTo const &other) |
| Copy assignment operator. | |
| BelongsTo & | operator= (BelongsTo &&other) noexcept |
| Move assignment operator. | |
| LIGHTWEIGHT_FORCE_INLINE constexpr void | SetModified (bool value) noexcept |
| Marks the field as modified or unmodified. | |
| LIGHTWEIGHT_FORCE_INLINE constexpr bool | IsModified () const noexcept |
| Checks if the field is modified. | |
| LIGHTWEIGHT_FORCE_INLINE constexpr ValueType const & | Value () const noexcept |
| Retrieves the reference to the value of the field. | |
| LIGHTWEIGHT_FORCE_INLINE constexpr ValueType & | MutableValue () noexcept |
| Retrieves the mutable reference to the value of the field. | |
| template<typename Self > requires (IsMandatory) | |
| LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & | Record (this Self &&self) |
| Retrieves a record from the relationship. When the record is not optional. | |
| template<typename Self > requires (IsOptional) | |
| LIGHTWEIGHT_FORCE_INLINE constexpr decltype(auto) | Record (this Self &&self) |
| template<typename Self > requires (IsMandatory) | |
| LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & | operator* (this Self &&self) noexcept |
| template<typename Self > requires (IsMandatory) | |
| LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord * | operator-> (this Self &&self) |
| LIGHTWEIGHT_FORCE_INLINE constexpr bool | operator! () const noexcept |
| Checks if the field value is NULL. | |
| LIGHTWEIGHT_FORCE_INLINE constexpr | operator bool () const noexcept |
| Checks if the field value is not NULL. | |
| LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & | EmplaceRecord () |
| Emplaces a record into the relationship. This will mark the relationship as loaded. | |
| LIGHTWEIGHT_FORCE_INLINE void | AdoptFetchedRecord (std::optional< ReferencedRecord > record) |
| template<typename Stmt > | |
| LIGHTWEIGHT_FORCE_INLINE void | BindOutputColumn (SQLSMALLINT outputIndex, Stmt &stmt) |
| Binds the foreign key value to the given output column index on the statement. | |
| std::weak_ordering | operator<=> (BelongsTo const &other) const noexcept |
| Three-way comparison operator. | |
| template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No> | |
| std::weak_ordering | operator<=> (Field< T, IsPrimaryKeyValue > const &other) const noexcept |
| Three-way comparison operator with a Field. | |
| bool | operator== (BelongsTo const &other) const noexcept |
| Equality comparison operator. | |
| bool | operator!= (BelongsTo const &other) const noexcept |
| Inequality comparison operator. | |
| template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No> | |
| bool | operator== (Field< T, IsPrimaryKeyValue > const &other) const noexcept |
| Equality comparison operator with a Field. | |
| template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No> | |
| bool | operator!= (Field< T, IsPrimaryKeyValue > const &other) const noexcept |
| Inequality comparison operator with a Field. | |
| void | SetAutoLoader (Loader loader) noexcept |
| Used internally to configure on-demand loading of the record. | |
Static Public Attributes | |
| static constexpr auto | ReferencedField = TheReferencedField |
| The field in the other record that references the current record. | |
| static constexpr std::string_view | ColumnNameOverride |
| If not an empty string, this value will be used as the column name in the database. | |
| static constexpr auto | IsOptional = Nullable == SqlNullable::Null |
| Indicates whether this relationship is optional (nullable). | |
| static constexpr auto | IsMandatory = !IsOptional |
| Indicates whether this relationship is mandatory (non-nullable). | |
| static constexpr auto | IsPrimaryKey = false |
| Indicates that a BelongsTo field is never a primary key. | |
| static constexpr auto | IsAutoIncrementPrimaryKey = false |
| Indicates that a BelongsTo field is never an auto-increment primary key. | |
Represents a one-to-one relationship.
The TheReferencedField parameter is the field in the other record that references the current record, in the form of &OtherRecord::Field. Other Field must be a primary key.
| TheReferencedField | The field in the other record that references the current record. |
| ColumnNameOverrideString | If not an empty string, this value will be used as the column name in the database. |
Definition at line 56 of file BelongsTo.hpp.
| using Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::ReferencedRecord = MemberClassType<decltype(TheReferencedField)> |
Represents the record type of the other field.
Definition at line 81 of file BelongsTo.hpp.
| using Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::BaseType = std::remove_cvref_t<decltype(std::declval<ReferencedRecord>().*ReferencedField)>::ValueType |
Represents the base column type of the foreign key, matching the primary key of the other record.
Definition at line 87 of file BelongsTo.hpp.
| using Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::ValueType = std::conditional_t<Nullable == SqlNullable::Null, std::optional<BaseType>, BaseType> |
Represents the value type of the foreign key, which can be either an optional or a non-optional type of the referenced field,
Definition at line 92 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Constructs a new BelongsTo with the given value(s) forwarded to the underlying value type.
Definition at line 106 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Constructs a new BelongsTo from the given referenced record, copying its primary key.
Definition at line 112 of file BelongsTo.hpp.
References Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::ReferencedField, and Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::Value().
|
inlineconstexprnoexcept |
Copy constructor.
Definition at line 124 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Move constructor.
Definition at line 134 of file BelongsTo.hpp.
|
inlinenoexcept |
Assigns NULL to the relationship, clearing the loaded record.
Definition at line 144 of file BelongsTo.hpp.
|
inline |
Assigns a referenced record, updating the foreign key and loaded state.
Definition at line 156 of file BelongsTo.hpp.
References Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::ReferencedField, and Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::Value().
|
inline |
Copy assignment operator.
Definition at line 176 of file BelongsTo.hpp.
|
inlinenoexcept |
Move assignment operator.
Definition at line 191 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Marks the field as modified or unmodified.
Definition at line 207 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Checks if the field is modified.
Definition at line 213 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Retrieves the reference to the value of the field.
Definition at line 219 of file BelongsTo.hpp.
Referenced by Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::BelongsTo(), and Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::operator=().
|
inlineconstexprnoexcept |
Retrieves the mutable reference to the value of the field.
Definition at line 225 of file BelongsTo.hpp.
|
inlineconstexpr |
Retrieves a record from the relationship. When the record is not optional.
Definition at line 234 of file BelongsTo.hpp.
|
inlineconstexpr |
Retrieves a record from the relationship. When the record is optional we return object similar to std::optional<ReferencedRecord&>
Definition at line 244 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Retrieves the record from the relationship. Only available when the relationship is mandatory.
Definition at line 260 of file BelongsTo.hpp.
|
inlineconstexpr |
Retrieves the record from the relationship. Only available when the relationship is mandatory.
Definition at line 270 of file BelongsTo.hpp.
|
inlineconstexprnoexcept |
Checks if the field value is NULL.
Definition at line 280 of file BelongsTo.hpp.
|
inlineexplicitconstexprnoexcept |
Checks if the field value is not NULL.
Definition at line 286 of file BelongsTo.hpp.
|
inlineconstexpr |
Emplaces a record into the relationship. This will mark the relationship as loaded.
Definition at line 292 of file BelongsTo.hpp.
|
inline |
Adopts an eagerly fetched referenced record, marking the relationship loaded.
This is the sink for a record that was already read from the database, as opposed to operator=(ReferencedRecord&), which establishes the relationship and therefore rewrites the foreign key and sets the modified flag. Here the foreign key is already whatever the row said it was, so it is deliberately left untouched and the field stays unmodified - adopting a fetched value is not a pending change to be written back.
An empty record leaves the relationship unloaded rather than clearing the foreign key: a mandatory relationship whose target row is missing is a data-integrity problem to be surfaced by the accessor, not silently turned into NULL.
| record | The fetched record, or std::nullopt if the referenced row was absent. |
Definition at line 312 of file BelongsTo.hpp.
|
inline |
Binds the foreign key value to the given output column index on the statement.
Definition at line 323 of file BelongsTo.hpp.
|
inlinenoexcept |
Three-way comparison operator.
Definition at line 329 of file BelongsTo.hpp.
|
inlinenoexcept |
Three-way comparison operator with a Field.
Definition at line 336 of file BelongsTo.hpp.
|
inlinenoexcept |
Equality comparison operator.
Definition at line 342 of file BelongsTo.hpp.
|
inlinenoexcept |
Inequality comparison operator.
Definition at line 348 of file BelongsTo.hpp.
|
inlinenoexcept |
Equality comparison operator with a Field.
Definition at line 355 of file BelongsTo.hpp.
|
inlinenoexcept |
Inequality comparison operator with a Field.
Definition at line 362 of file BelongsTo.hpp.
|
inlinenoexcept |
Used internally to configure on-demand loading of the record.
Definition at line 373 of file BelongsTo.hpp.
|
staticconstexpr |
The field in the other record that references the current record.
Definition at line 60 of file BelongsTo.hpp.
Referenced by Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::BelongsTo(), and Lightweight::BelongsTo< TheReferencedField, ColumnNameOverrideString, Nullable >::operator=().
|
staticconstexpr |
If not an empty string, this value will be used as the column name in the database.
Definition at line 63 of file BelongsTo.hpp.
|
staticconstexpr |
Indicates whether this relationship is optional (nullable).
Definition at line 95 of file BelongsTo.hpp.
|
staticconstexpr |
Indicates whether this relationship is mandatory (non-nullable).
Definition at line 97 of file BelongsTo.hpp.
|
staticconstexpr |
Indicates that a BelongsTo field is never a primary key.
Definition at line 99 of file BelongsTo.hpp.
|
staticconstexpr |
Indicates that a BelongsTo field is never an auto-increment primary key.
Definition at line 101 of file BelongsTo.hpp.