session and insert query builder has many to many progress

This commit is contained in:
2026-04-22 09:15:57 +02:00
parent 59e1533cca
commit 78eb5d04cd
5 changed files with 89 additions and 23 deletions
+38
View File
@@ -18,6 +18,7 @@
#include "../../models/book.hpp"
#include "../../models/airplane.hpp"
#include "../../models/flight.hpp"
#include "../../models/recipe.hpp"
using namespace matador::object;
using namespace matador::sql;
@@ -112,4 +113,41 @@ TEST_CASE("Test insert builder has many", "[query][insert_query_builder][has_man
const auto& stmts = *build_result;
REQUIRE_FALSE(stmts.empty());
REQUIRE(stmts.size() == 6);
}
TEST_CASE("Test insert builder has many to many", "[query][insert_query_builder][many_to_many]") {
using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm;
const auto result = scm.attach<recipe>("recipes")
.and_then( [&scm] { return scm.attach<ingredient>("ingredients"); } );
REQUIRE(result.is_ok());
const std::vector ingredients {
make_object<ingredient>(1, "Apple"),
make_object<ingredient>(2, "Strawberry"),
make_object<ingredient>(3, "Pineapple"),
make_object<ingredient>(4, "Sugar"),
make_object<ingredient>(5, "Flour"),
make_object<ingredient>(6, "Butter"),
make_object<ingredient>(7, "Beans")
};
std::vector recipes {
make_object<recipe>(1, "Apple Pie", std::vector{ingredients[0], ingredients[3], ingredients[4]}),
make_object<recipe>(2, "Strawberry Cake", std::vector{ingredients[5], ingredients[6]}),
make_object<recipe>(3, "Pineapple Pie", std::vector{ingredients[0], ingredients[1], ingredients[2]})
};
const auto contexts_by_type = to_contexts_by_name(scm, db.dialect());
insert_query_builder<recipe> iqb(scm, contexts_by_type);
auto build_result = iqb.build(recipes[0]);
REQUIRE(build_result.is_ok());
const auto& stmts = *build_result;
REQUIRE_FALSE(stmts.empty());
REQUIRE(stmts.size() == 7);
}