From 833cb6435285f812c344b02931a7d17eb2af7a30 Mon Sep 17 00:00:00 2001 From: sascha Date: Fri, 27 Mar 2026 15:10:03 +0100 Subject: [PATCH] added test for session insert --- test/backends/SessionInsertHasMany.cpp | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/backends/SessionInsertHasMany.cpp diff --git a/test/backends/SessionInsertHasMany.cpp b/test/backends/SessionInsertHasMany.cpp new file mode 100644 index 0000000..ea2f36a --- /dev/null +++ b/test/backends/SessionInsertHasMany.cpp @@ -0,0 +1,30 @@ +#include "catch2/catch_test_macros.hpp" + +#include "SessionFixture.hpp" + +#include "models/author.hpp" +#include "models/book.hpp" + +using namespace matador; +using namespace matador::object; +using namespace matador::test; + +TEST_CASE_METHOD(SessionFixture, "Test insert object with has many relation", "[session][insert][has_many]") { + auto result = schema.attach("books") + .and_then( [this] { return schema.attach("authors"); } ) + .and_then([this] { return schema.create(db); } ); + REQUIRE(result.is_ok()); + + schema.initialize_executor(ses); + + auto s_king = make_object(1, "Steven", "King", "21.9.1947", 1956, false); + + s_king->books.push_back(make_object(2, "Carrie", object_ptr{}, 1974)); + s_king->books.push_back(make_object(3, "The Shining", object_ptr{}, 1977)); + s_king->books.push_back(make_object(4, "It", object_ptr{}, 1986)); + s_king->books.push_back(make_object(5, "Misery", object_ptr{}, 1987)); + s_king->books.push_back(make_object(6, "The Dark Tower: The Gunslinger", object_ptr{}, 1982)); + + auto res = ses.insert(s_king); + REQUIRE(res.is_ok()); +} \ No newline at end of file