collection resolver progress

This commit is contained in:
2026-02-01 13:17:40 +01:00
parent c838e9dd7b
commit f9333158e2
21 changed files with 247 additions and 192 deletions
+15 -9
View File
@@ -588,10 +588,8 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
}
TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "[query][has_many][lazy]") {
// auto result = repo.attach<author>("authors")
// .and_then( [this] { return repo.attach<book>("books"); } )
auto result = repo.attach<book>("books")
.and_then( [this] { return repo.attach<author>("authors"); } )
auto result = repo.attach<author>("authors")
.and_then( [this] { return repo.attach<book>("books"); } )
.and_then([this] {
return repo.create(db);
} );
@@ -662,6 +660,13 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "
REQUIRE(a->year_of_birth == authors.at(index)->year_of_birth);
REQUIRE(a->distinguished == authors.at(index)->distinguished);
REQUIRE(!a->books.empty());
for (const auto& b : a->books) {
const auto title = b->title;
// REQUIRE(b->id == books.at(index)->id);
// REQUIRE(b->title == books.at(index)->title);
// REQUIRE(b->author_id == books.at(index)->author_id);
// REQUIRE(b->published_in == books.at(index)->published_in);
}
++index;
}
}
@@ -735,11 +740,12 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy belongs to relation",
}
TEST_CASE_METHOD(QueryFixture, "Test load entity with eager belongs to relation", "[query][belongs_to][eager]") {
auto result = repo.attach<author>("authors")
.and_then( [this] { return repo.attach<book>("books"); } )
.and_then([this] {
return repo.create(db);
} );
// auto result = repo.attach<author>("authors")
// .and_then( [this] { return repo.attach<book>("books"); } )
auto result = repo.attach<book>("books")
.and_then( [this] { return repo.attach<author>("authors"); })
.and_then([this] { return repo.create(db); });
REQUIRE(result.is_ok());
const std::vector authors {
object_ptr{std::make_shared<author>(1, "Michael", "Crichton", "23.10.1942", 1975, true)},
+4 -2
View File
@@ -17,8 +17,10 @@ TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema][one-to-man
using namespace matador::test;
query::schema repo;
auto result = repo.attach<department>("departments")
.and_then([&repo] { return repo.attach<employee>("employees"); });
// auto result = repo.attach<department>("departments")
// .and_then([&repo] { return repo.attach<employee>("employees"); });
auto result = repo.attach<employee>("employees")
.and_then([&repo] { return repo.attach<department>("departments"); });
REQUIRE(result);
auto conn = pool.acquire();
+10 -4
View File
@@ -165,9 +165,12 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][f
}
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-many lazy relation", "[session][find][one-to-many][eager]") {
auto result = schema.attach<author>("authors")
.and_then( [this] { return schema.attach<book>("books"); } )
// auto result = schema.attach<author>("authors")
// .and_then( [this] { return schema.attach<book>("books"); } )
auto result = schema.attach<book>("books")
.and_then( [this] { return schema.attach<author>("authors"); } )
.and_then([this] { return schema.create(db); } );
REQUIRE(result.is_ok());
schema.initialize_executor(ses);
std::vector authors {
@@ -217,11 +220,14 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
}
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-many eager relation", "[session][find][one-to-many][eager]") {
auto result = schema.attach<department>("departments")
.and_then( [this] { return schema.attach<employee>("employees"); } )
// auto result = repo.attach<department>("departments")
// .and_then([this] { return repo.attach<employee>("employees"); })
auto result = schema.attach<employee>("employees")
.and_then([this] { return schema.attach<department>("departments"); })
.and_then([this] {
return schema.create(db);
} );
REQUIRE(result.is_ok());
std::vector<std::unique_ptr<department>> departments;
departments.emplace_back(new department{1, "Insurance"});
+2 -3
View File
@@ -6,8 +6,7 @@
#include "matador/utils/access.hpp"
#include "matador/object/object_ptr.hpp"
#include <vector>
#include "matador/object/collection.hpp"
namespace matador::test {
struct order {
@@ -23,7 +22,7 @@ struct order {
std::string ship_region;
std::string ship_postal_code;
std::string ship_country;
std::vector<object::object_ptr<order_details> > order_details_;
object::collection<object::object_ptr<order_details> > order_details_;
template<class Operator>
void process(Operator &op) {
+1
View File
@@ -52,6 +52,7 @@ utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> test_connec
return utils::ok(std::make_unique<sql::query_result_impl>(std::make_unique<test_result_reader>(),
context.prototype,
context.resolver,
context.result_type,
context.prototype.size()));
}
+1
View File
@@ -22,6 +22,7 @@ utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> test_statem
return utils::ok(std::make_unique<sql::query_result_impl>(std::make_unique<test_result_reader>(),
query_.prototype,
query_.resolver,
query_.result_type,
query_.prototype.size()));
}