insert_query_builder has_many progress
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "../backend/test_backend_service.hpp"
|
||||
|
||||
#include "../../models/author.hpp"
|
||||
#include "../../models/book.hpp"
|
||||
#include "../../models/airplane.hpp"
|
||||
#include "../../models/flight.hpp"
|
||||
|
||||
@@ -32,8 +34,8 @@ TEST_CASE("insert query builder test", "[query][insert_query_builder]") {
|
||||
|
||||
insert_query_builder iqb(scm);
|
||||
|
||||
const auto a380 = object_ptr(std::make_shared<airplane>(1, "Boeing", "A380" ));
|
||||
auto build_result = iqb.build<airplane>(a380);
|
||||
const auto a380 = make_object<airplane>(1, "Boeing", "A380" );
|
||||
auto build_result = iqb.build(a380);
|
||||
REQUIRE(build_result.is_ok());
|
||||
|
||||
const auto& stmts = *build_result;
|
||||
@@ -45,3 +47,30 @@ TEST_CASE("insert query builder test", "[query][insert_query_builder]") {
|
||||
const auto sql = std::get<executable_query>(step.query).str(db);
|
||||
REQUIRE(sql == R"(INSERT INTO "airplanes" ("id", "brand", "model") VALUES (1, 'Boeing', 'A380'))");
|
||||
}
|
||||
|
||||
TEST_CASE("Test insert builder has many", "[query][insert_query_builder][has_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<book>("books")
|
||||
.and_then( [&scm] { return scm.attach<author>("authors"); } );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
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));
|
||||
|
||||
insert_query_builder iqb(scm);
|
||||
|
||||
auto build_result = iqb.build(s_king);
|
||||
REQUIRE(build_result.is_ok());
|
||||
|
||||
const auto& stmts = *build_result;
|
||||
REQUIRE(stmts.size() == 1);
|
||||
}
|
||||
Reference in New Issue
Block a user