From 2e1b58374138bca8a3a2e612d93f7f28a8801b68 Mon Sep 17 00:00:00 2001 From: sascha Date: Tue, 26 May 2026 15:49:49 +0200 Subject: [PATCH] moved recipe and ingredient pk generators into recipe.hpp --- .../SessionInsertHasManyToManyTest.cpp | 60 ------------------- test/models/recipe.hpp | 58 ++++++++++++++++++ 2 files changed, 58 insertions(+), 60 deletions(-) diff --git a/test/backends/SessionInsertHasManyToManyTest.cpp b/test/backends/SessionInsertHasManyToManyTest.cpp index 9af5e75..ff75e1c 100644 --- a/test/backends/SessionInsertHasManyToManyTest.cpp +++ b/test/backends/SessionInsertHasManyToManyTest.cpp @@ -14,66 +14,6 @@ using namespace matador::object; using namespace matador::test; using namespace matador::query::meta; -namespace matador::test { -template -struct recipe_pk_generator; - -template -struct ingredient_pk_generator { - unsigned int id{}; - std::string name; - collection>> recipes{}; - - ingredient_pk_generator() = default; - - explicit ingredient_pk_generator(std::string name) - : name(std::move(name)) { - } - - ingredient_pk_generator(std::string name, std::vector>> recps) - : name(std::move(name)) - , recipes(std::move(recps)){} - - template - void process(Operator &op) { - namespace field = matador::access; - field::primary_key(op, "id", id, PkAttribute); - field::attribute(op, "name", name, UniqueVarChar255); - field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager); - } -}; - -template -struct recipe_pk_generator { - unsigned int id{}; - std::string name; - collection>> ingredients{}; - - recipe_pk_generator() = default; - explicit recipe_pk_generator(std::string name) - : name(std::move(name)) { - } - recipe_pk_generator(std::string name, std::vector>> ings) - : name(std::move(name)) - , ingredients(std::move(ings)){} - - template - void process(Operator &op) { - namespace field = matador::access; - field::primary_key(op, "id", id, PkAttribute); - field::attribute(op, "name", name, UniqueVarChar255); - field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy); - } -}; - -using ingredient_identity = ingredient_pk_generator; -using ingredient_table = ingredient_pk_generator; -using ingredient_sequence = ingredient_pk_generator; -using recipe_identity = recipe_pk_generator; -using recipe_table = recipe_pk_generator; -using recipe_sequence = recipe_pk_generator; -} - TEST_CASE_METHOD(SessionFixture, "Test insert object with has many to many relation", "[session][insert][has_many_to_many]") { auto result = schema.attach("recipes") .and_then( [this] { return schema.attach("ingredients"); } ) diff --git a/test/models/recipe.hpp b/test/models/recipe.hpp index 56258a6..e308b81 100644 --- a/test/models/recipe.hpp +++ b/test/models/recipe.hpp @@ -57,6 +57,64 @@ struct recipe { field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy); } }; + +template +struct recipe_pk_generator; + +template +struct ingredient_pk_generator { + unsigned int id{}; + std::string name; + object::collection>> recipes{}; + + ingredient_pk_generator() = default; + + explicit ingredient_pk_generator(std::string name) + : name(std::move(name)) { + } + + ingredient_pk_generator(std::string name, std::vector>> recps) + : name(std::move(name)) + , recipes(std::move(recps)){} + + template + void process(Operator &op) { + namespace field = matador::access; + field::primary_key(op, "id", id, PkAttribute); + field::attribute(op, "name", name, UniqueVarChar255); + field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager); + } +}; + +template +struct recipe_pk_generator { + unsigned int id{}; + std::string name; + object::collection>> ingredients{}; + + recipe_pk_generator() = default; + explicit recipe_pk_generator(std::string name) + : name(std::move(name)) { + } + recipe_pk_generator(std::string name, std::vector>> ings) + : name(std::move(name)) + , ingredients(std::move(ings)){} + + template + void process(Operator &op) { + namespace field = matador::access; + field::primary_key(op, "id", id, PkAttribute); + field::attribute(op, "name", name, UniqueVarChar255); + field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy); + } +}; + +using ingredient_identity = ingredient_pk_generator; +using ingredient_table = ingredient_pk_generator; +using ingredient_sequence = ingredient_pk_generator; +using recipe_identity = recipe_pk_generator; +using recipe_table = recipe_pk_generator; +using recipe_sequence = recipe_pk_generator; } #endif //QUERY_RECIPE_HPP