query/test/backends/SessionInsertHasMany.cpp

30 lines
1.1 KiB
C++

#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<book>("books")
.and_then( [this] { return schema.attach<author>("authors"); } )
.and_then([this] { return schema.create(db); } );
REQUIRE(result.is_ok());
schema.initialize_executor(ses);
auto s_king = make_object<author>(1, "Steven", "King", "21.9.1947", 1956, false);
s_king->books.push_back(make_object<book>(2, "Carrie", object_ptr<author>{}, 1974));
s_king->books.push_back(make_object<book>(3, "The Shining", object_ptr<author>{}, 1977));
s_king->books.push_back(make_object<book>(4, "It", object_ptr<author>{}, 1986));
s_king->books.push_back(make_object<book>(5, "Misery", object_ptr<author>{}, 1987));
s_king->books.push_back(make_object<book>(6, "The Dark Tower: The Gunslinger", object_ptr<author>{}, 1982));
auto res = ses.insert(s_king);
REQUIRE(res.is_ok());
}