diff --git a/include/orm/tiny/concerns/hasrelationstore.hpp b/include/orm/tiny/concerns/hasrelationstore.hpp index 14032f89a..7a3ebeb21 100644 --- a/include/orm/tiny/concerns/hasrelationstore.hpp +++ b/include/orm/tiny/concerns/hasrelationstore.hpp @@ -21,9 +21,6 @@ TINYORM_BEGIN_COMMON_NAMESPACE namespace Orm::Tiny::Concerns { - template - class HasRelationships; - // FUTURE relationstore, cache results, eg. cache Relation instance and return copy of this cached Relation instance, Related parameter can be obtained from cached Relation instance silverqx /*! Relation store, handles mapping from a relation name to the Model's relation method, also calls visited method with Related parameter when needed. */ diff --git a/include/orm/tiny/support/stores/baserelationstore.hpp b/include/orm/tiny/support/stores/baserelationstore.hpp index 73ca8b2c9..b2a2382a2 100644 --- a/include/orm/tiny/support/stores/baserelationstore.hpp +++ b/include/orm/tiny/support/stores/baserelationstore.hpp @@ -17,6 +17,9 @@ namespace Concerns { template class HasRelationStore; + + template + class HasRelationships; } namespace Relations { @@ -82,6 +85,8 @@ namespace Support::Stores { Q_DISABLE_COPY(BaseRelationStore) + // To access visit() + friend Concerns::HasRelationships; // To access operator() friend Derived; @@ -95,6 +100,9 @@ namespace Support::Stores TINY_RELATIONSTORES_ALIASES + // To access visit() + friend BelongsToManyRelatedTableStore; + protected: /*! Constructor. */ BaseRelationStore(NotNull hasRelationStore, @@ -104,9 +112,6 @@ namespace Support::Stores /*! Default destructor. */ inline ~BaseRelationStore() = default; - /*! Visit the given relation. */ - void visit(const QString &relation); - protected: /*! Called from Model::u_relations to pass reference to the relation method, an enter point of the visitation. */ @@ -116,9 +121,6 @@ namespace Support::Stores /*! Currently held store type. */ inline RelationStoreType getStoreType() const noexcept; - /*! Reference to the parent HasRelationStore instance. */ - NotNull m_hasRelationStore; - /* Static cast this to a child's instance type (CRTP) */ /*! Static cast this to a child's instance type (CRTP). */ inline Derived &model() noexcept; @@ -131,6 +133,11 @@ namespace Support::Stores inline const Model &basemodel() const noexcept; private: + /*! Visit the given relation. */ + void visit(const QString &relation); + + /*! Reference to the parent HasRelationStore instance. */ + NotNull m_hasRelationStore; /*! Store type held by relation store. */ /*const*/ RelationStoreType m_storeType; }; @@ -148,12 +155,6 @@ namespace Support::Stores /* public */ - template - void BaseRelationStore::visit(const QString &relation) - { - std::invoke(basemodel().getUserRelations().find(relation).value(), *this); - } - template template Method> void BaseRelationStore::operator()(const Method method) @@ -266,6 +267,14 @@ namespace Support::Stores return m_hasRelationStore->basemodel(); } + /* private */ + + template + void BaseRelationStore::visit(const QString &relation) + { + std::invoke(basemodel().getUserRelations().find(relation).value(), *this); + } + } // namespace Support::Stores } // namespace Orm::Tiny diff --git a/include/orm/tiny/support/stores/belongstomanyrelatedtablestore.hpp b/include/orm/tiny/support/stores/belongstomanyrelatedtablestore.hpp index 087c056e7..46bf522d3 100644 --- a/include/orm/tiny/support/stores/belongstomanyrelatedtablestore.hpp +++ b/include/orm/tiny/support/stores/belongstomanyrelatedtablestore.hpp @@ -28,6 +28,9 @@ namespace Support::Stores { Q_DISABLE_COPY(BelongsToManyRelatedTableStore) + // To access visitWithResult() + friend Concerns::HasRelationships; + /*! Alias for the helper utils. */ using Helpers = Orm::Utils::Helpers; /*! Alias for the NotNull. */ @@ -49,10 +52,10 @@ namespace Support::Stores /*! Default destructor. */ inline ~BelongsToManyRelatedTableStore() = default; + private: /*! Visit the given relation and return a result. */ std::optional visitWithResult(const QString &relation); - private: /*! Method called after visitation. */ template Method> void visited(Method /*unused*/); diff --git a/include/orm/tiny/support/stores/lazyrelationstore.hpp b/include/orm/tiny/support/stores/lazyrelationstore.hpp index 799d8a377..904ee556a 100644 --- a/include/orm/tiny/support/stores/lazyrelationstore.hpp +++ b/include/orm/tiny/support/stores/lazyrelationstore.hpp @@ -18,6 +18,8 @@ namespace Orm::Tiny::Support::Stores { Q_DISABLE_COPY(LazyRelationStore) + // To access result() + friend Concerns::HasRelationships; /*! Alias for the NotNull. */ template using NotNull = Orm::Utils::NotNull; @@ -36,11 +38,11 @@ namespace Orm::Tiny::Support::Stores /*! Default destructor. */ inline ~LazyRelationStore() = default; + private: /*! Get the result of lazy load. */ inline const std::variant, std::optional> & result() const noexcept; - private: /*! Method called after visitation. */ template Method> void visited(Method method); diff --git a/include/orm/tiny/support/stores/pushrelationstore.hpp b/include/orm/tiny/support/stores/pushrelationstore.hpp index e4b5c7c8e..c22ba8458 100644 --- a/include/orm/tiny/support/stores/pushrelationstore.hpp +++ b/include/orm/tiny/support/stores/pushrelationstore.hpp @@ -18,6 +18,8 @@ namespace Orm::Tiny::Support::Stores { Q_DISABLE_COPY(PushRelationStore) + // To access result(), setResult(), and models() + friend Concerns::HasRelationships; /*! Alias for the NotNull. */ template using NotNull = Orm::Utils::NotNull; @@ -37,6 +39,7 @@ namespace Orm::Tiny::Support::Stores /*! Default destructor. */ inline ~PushRelationStore() = default; + private: /*! Get the result of a push. */ inline bool result() const noexcept; /*! Set the result of a push. */ @@ -45,7 +48,6 @@ namespace Orm::Tiny::Support::Stores /*! Get models to push, the reference to the relation in the m_relations hash. */ inline RelationsType &models() const noexcept; - private: /*! Method called after visitation. */ template Method> void visited(Method /*unused*/) const;