5#include "../SqlStatement.hpp"
22template <
typename OtherTable,
typename ThroughTable>
35 LIGHTWEIGHT_FORCE_INLINE
constexpr void EmplaceRecord(std::shared_ptr<ReferencedRecord> record) { _record = std::move(record); }
38 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr ReferencedRecord&
Record() noexcept { RequireLoaded();
return *_record.get(); }
41 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr ReferencedRecord const&
Record() const noexcept { RequireLoaded();
return *_record.get(); }
44 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr bool IsLoaded() const noexcept {
return _record.get() !=
nullptr; }
47 LIGHTWEIGHT_FORCE_INLINE
void Unload() noexcept { _record = std::nullopt; }
55 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr ReferencedRecord const&
operator*() const noexcept { RequireLoaded();
return *_record; }
63 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr ReferencedRecord const*
operator->() const noexcept { RequireLoaded();
return &_record.get(); }
66 std::weak_ordering operator<=>(
HasOneThrough const& other)
const noexcept =
default;
70 std::function<void()> loadReference {};
76 _loader = std::move(loader);
80 void RequireLoaded()
const
85 if (_loader.loadReference)
86 _loader.loadReference();
95 std::shared_ptr<ReferencedRecord> _record {};
100 template <
typename T>
101 struct IsHasOneThrough: std::false_type
105 template <
typename OtherTable,
typename ThroughTable>
106 struct IsHasOneThrough<HasOneThrough<OtherTable, ThroughTable>>: std::true_type
112constexpr bool IsHasOneThrough = detail::IsHasOneThrough<std::remove_cvref_t<T>>::value;
Represents a one-to-one relationship through a join table.
LIGHTWEIGHT_FORCE_INLINE constexpr void EmplaceRecord(std::shared_ptr< ReferencedRecord > record)
Emplaces the given record into this relationship.
LIGHTWEIGHT_FORCE_INLINE void Unload() noexcept
Unloads the record from memory.
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord * operator->() noexcept
Retrieves the record in this relationship.
ThroughTable ThroughRecord
The record type of the "through" side of the relationship.
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & operator*() noexcept
Retrieves the record in this relationship.
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & Record() noexcept
Retrieves the record in this relationship.
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & operator*() const noexcept
Retrieves the record in this relationship.
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const * operator->() const noexcept
Retrieves the record in this relationship.
LIGHTWEIGHT_FORCE_INLINE constexpr bool IsLoaded() const noexcept
Checks if the record is loaded.
OtherTable ReferencedRecord
The record type of the "Other" side of the relationship.
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & Record() const noexcept
Retrieves the record in this relationship.
void SetAutoLoader(Loader loader)
Used internally to configure on-demand loading of the record.
Represents an error when a record is required to be loaded but is not.