has many to many progress

This commit is contained in:
2025-02-24 07:26:54 +01:00
parent 35f078bbc4
commit 261f9fd6cb
3 changed files with 62 additions and 19 deletions
+35
View File
@@ -7,6 +7,7 @@
#include "models/book.hpp"
#include "models/department.hpp"
#include "models/flight.hpp"
#include "models/recipe.hpp"
#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";
}
}
}
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"));
}