#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]") { const 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()); }