33 lines
1.2 KiB
C++
33 lines
1.2 KiB
C++
#include "catch2/catch_test_macros.hpp"
|
|
|
|
#include "SessionFixture.hpp"
|
|
|
|
#include "connection.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<book>("books")
|
|
.and_then( [this] { return schema.attach<author>("authors"); } )
|
|
.and_then([this] { return schema.create(db); } );
|
|
REQUIRE(result.is_ok());
|
|
|
|
orm::session ses({bus, connection::dns, 4}, schema);
|
|
schema.initialize(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());
|
|
} |