has many to many progress

This commit is contained in:
Sascha Kühl 2025-02-24 07:26:54 +01:00
parent 35f078bbc4
commit 261f9fd6cb
3 changed files with 62 additions and 19 deletions

View File

@ -7,6 +7,7 @@
#include "models/book.hpp" #include "models/book.hpp"
#include "models/department.hpp" #include "models/department.hpp"
#include "models/flight.hpp" #include "models/flight.hpp"
#include "models/recipe.hpp"
#include <iostream> #include <iostream>
@ -202,4 +203,38 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
std::cout << "\temployee: " << emp->first_name << " " << emp->last_name << "( " << emp->id << ")\n"; std::cout << "\temployee: " << emp->first_name << " " << emp->last_name << "( " << emp->id << ")\n";
} }
} }
}
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with many-to-many eager relation", "[session][find][many-to-many][eager]") {
auto result = ses.attach<recipe>("recipes")
.and_then( [this] { return ses.attach<ingredient>("ingredients"); } )
.and_then( [this] { return ses.attach<recipe_ingredient>("recipe_ingredients"); } )
.and_then( [this] { return ses.create_schema(); } );
tables_to_drop.emplace("recipes");
tables_to_drop.emplace("ingredients");
tables_to_drop.emplace("recipe_ingredients");
std::vector<std::unique_ptr<ingredient>> ingredients;
ingredients.push_back(std::make_unique<ingredient>(1, "Apple"));
ingredients.push_back(std::make_unique<ingredient>(1, "Apple"));
ingredients.push_back(std::make_unique<ingredient>(2, "Strawberry"));
ingredients.push_back(std::make_unique<ingredient>(3, "Pineapple"));
ingredients.push_back(std::make_unique<ingredient>(4, "Sugar"));
ingredients.push_back(std::make_unique<ingredient>(5, "Flour"));
ingredients.push_back(std::make_unique<ingredient>(6, "Butter"));
ingredients.push_back(std::make_unique<ingredient>(7, "Beans"));
for (auto &i: ingredients) {
auto res = ses.insert(i.release());
REQUIRE(res.is_ok());
}
std::vector<std::unique_ptr<recipe>> recipes;
recipes.push_back(std::make_unique<recipe>(7, "Apple Crumble"));
recipes.push_back(std::make_unique<recipe>(8, "Beans Chili"));
recipes.push_back(std::make_unique<recipe>(9, "Fruit Salad"));
} }

View File

@ -18,6 +18,10 @@ struct ingredient
std::string name; std::string name;
std::vector<object::object_ptr<recipe>> recipes{}; std::vector<object::object_ptr<recipe>> recipes{};
ingredient()= default;
ingredient(const unsigned int id, std::string name)
: id(id), name(std::move(name)) {}
template<class Operator> template<class Operator>
void process(Operator &op) { void process(Operator &op) {
namespace field = matador::access; namespace field = matador::access;
@ -33,6 +37,10 @@ struct recipe
std::string name; std::string name;
std::vector<object::object_ptr<ingredient>> ingredients{}; std::vector<object::object_ptr<ingredient>> ingredients{};
recipe()= default;
recipe(const unsigned int id, std::string name)
: id(id), name(std::move(name)) {}
template<class Operator> template<class Operator>
void process(Operator &op) { void process(Operator &op) {
namespace field = matador::access; namespace field = matador::access;

View File

@ -1,23 +1,23 @@
#include "test_parameter_binder.hpp" #include "test_parameter_binder.hpp"
namespace matador::test::orm { namespace matador::test::orm {
void test_parameter_binder::write_value(size_t pos, const int8_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const int8_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const int16_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const int16_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const int32_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const int32_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const int64_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const int64_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const uint8_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const uint8_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const uint16_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const uint16_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const uint32_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const uint32_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const uint64_t &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const uint64_t &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const bool &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const bool &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const float &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const float &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const double &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const double &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const time &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const time &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const date &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const date &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const char *x) {} void test_parameter_binder::write_value(size_t /*pos*/, const char * /*x*/) {}
void test_parameter_binder::write_value(size_t pos, const char *x, size_t size) {} void test_parameter_binder::write_value(size_t /*pos*/, const char * /*x*/, size_t /*size*/) {}
void test_parameter_binder::write_value(size_t pos, const std::string &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const std::string &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const std::string &x, size_t size) {} void test_parameter_binder::write_value(size_t /*pos*/, const std::string &/*x*/, size_t /*size*/) {}
void test_parameter_binder::write_value(size_t pos, const utils::blob &x) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::blob &/*x*/) {}
void test_parameter_binder::write_value(size_t pos, const utils::value &x, size_t size) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::value &/*x*/, size_t /*size*/) {}
} }