insert query builder has many to many progress
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#include "catch2/catch_test_macros.hpp"
|
||||
|
||||
#include "SessionFixture.hpp"
|
||||
|
||||
#include "connection.hpp"
|
||||
|
||||
#include "models/recipe.hpp"
|
||||
|
||||
using namespace matador;
|
||||
using namespace matador::object;
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Test insert object with has many to many relation", "[session][insert][has_many_to_many]") {
|
||||
auto result = schema.attach<recipe>("recipes")
|
||||
.and_then( [this] { return schema.attach<ingredient>("ingredients"); } )
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
|
||||
orm::session ses({bus, connection::dns, 4}, schema);
|
||||
|
||||
std::vector ingredients {
|
||||
make_object<ingredient>(1, "Apple"),
|
||||
make_object<ingredient>(2, "Strawberry"),
|
||||
make_object<ingredient>(3, "Pineapple"),
|
||||
make_object<ingredient>(4, "Sugar"),
|
||||
make_object<ingredient>(5, "Flour"),
|
||||
make_object<ingredient>(6, "Butter"),
|
||||
make_object<ingredient>(7, "Beans")
|
||||
};
|
||||
|
||||
std::vector recipes {
|
||||
make_object<recipe>(1, "Apple Pie", std::vector{ingredients[0], ingredients[3], ingredients[4]}),
|
||||
make_object<recipe>(2, "Strawberry Cake", std::vector{ingredients[5], ingredients[6]}),
|
||||
make_object<recipe>(3, "Pineapple Pie", std::vector{ingredients[0], ingredients[1], ingredients[2]})
|
||||
};
|
||||
|
||||
for (auto &r: recipes) {
|
||||
auto res = ses.insert(r);
|
||||
REQUIRE(res.is_ok());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user