collection has-many-to-many resolve progress
This commit is contained in:
+36
-16
@@ -821,6 +821,10 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
.and_then( [this] { return repo.attach<recipe>("recipes"); } )
|
||||
.and_then([this] {return repo.create(db); });
|
||||
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
repo.initialize_executor(db);
|
||||
|
||||
REQUIRE(db.exists(RECIPE.table_name()));
|
||||
REQUIRE(db.exists(INGREDIENT.table_name()));
|
||||
REQUIRE(db.exists(RECIPE_INGREDIENT.table_name()));
|
||||
@@ -845,9 +849,9 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
}
|
||||
|
||||
std::vector<recipe> recipes{
|
||||
{7, "Apple Crumble"},
|
||||
{8, "Beans Chili"},
|
||||
{9, "Fruit Salad"}
|
||||
{8, "Apple Crumble"},
|
||||
{9, "Beans Chili"},
|
||||
{10, "Fruit Salad"}
|
||||
};
|
||||
|
||||
for (const auto &r: recipes) {
|
||||
@@ -860,14 +864,14 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
}
|
||||
|
||||
std::vector<std::pair<int, int>> recipe_ingredients {
|
||||
{ 7, 1 },
|
||||
{ 7, 4 },
|
||||
{ 7, 5 },
|
||||
{ 8, 6 },
|
||||
{ 8, 7 },
|
||||
{ 9, 1 },
|
||||
{ 9, 2 },
|
||||
{ 9, 3 }
|
||||
{ 8, 1 },
|
||||
{ 8, 4 },
|
||||
{ 8, 5 },
|
||||
{ 9, 6 },
|
||||
{ 9, 7 },
|
||||
{ 10, 1 },
|
||||
{ 10, 2 },
|
||||
{ 10, 3 }
|
||||
};
|
||||
|
||||
for (const auto & [recipe_id, ingredient_id]: recipe_ingredients) {
|
||||
@@ -883,15 +887,31 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
const auto ri= RECIPE_INGREDIENT.as("ri");
|
||||
const auto i = INGREDIENT.as("i");
|
||||
|
||||
auto ingredients_result = query::select({r.id, r.name, ri.ingredient_id, i.name})
|
||||
auto recipes_result = query::select({r.id, r.name })
|
||||
.from(r)
|
||||
.join_left(ri).on(r.id == ri.recipe_id)
|
||||
.join_left(i).on(ri.ingredient_id == i.id)
|
||||
.order_by({r.id}).asc()
|
||||
.fetch_all<recipe>(db);
|
||||
REQUIRE(recipes_result.is_ok());
|
||||
|
||||
for (const auto &reps : *recipes_result) {
|
||||
REQUIRE(!reps->ingredients.empty());
|
||||
for (const auto &ingr : reps->ingredients) {
|
||||
std::cout << ingr->name << " (" << reps->name << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
auto ingredients_result = query::select({i.id, i.name, ri.recipe_id, r.name})
|
||||
.from(i)
|
||||
.join_left(ri).on(i.id == ri.ingredient_id)
|
||||
.join_left(r).on(ri.recipe_id == r.id)
|
||||
.order_by({i.id, r.id}).asc()
|
||||
.fetch_all<ingredient>(db);
|
||||
REQUIRE(ingredients_result.is_ok());
|
||||
|
||||
for (const auto &ing : *ingredients_result) {
|
||||
REQUIRE(!ing->recipes.empty());
|
||||
for (const auto &ingr : *ingredients_result) {
|
||||
REQUIRE(!ingr->recipes.empty());
|
||||
for (const auto &recipe : ingr->recipes) {
|
||||
std::cout << recipe->name << " (" << ingr->name << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user