has many fetch with join

This commit is contained in:
Sascha Kühl
2025-02-19 14:51:42 +01:00
parent 784f6e768d
commit 8ab8274d93
19 changed files with 264 additions and 52 deletions
+4 -1
View File
@@ -197,6 +197,9 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
all_departments = find_result.release();
for (auto it = all_departments.begin(); it != all_departments.end(); ++it) {
std::cout << "department: " << it->name << " (employees: " << it->employees.size() << ")\n";
std::cout << "department: " << it->name << " (id: " << it->id << ", employees: " << it->employees.size() << ")\n";
for (const auto& emp : it->employees) {
std::cout << "\temployee: " << emp->first_name << " " << emp->last_name << "( " << emp->id << ")\n";
}
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ struct employee {
field::primary_key(op, "id", id);
field::attribute(op, "first_name", first_name, 63);
field::attribute(op, "last_name", last_name, 63);
field::belongs_to(op, "dep_id", dep, utils::fetch_type::EAGER);
field::belongs_to(op, "dep_id", dep, utils::fetch_type::LAZY);
}
};
+1 -1
View File
@@ -28,7 +28,7 @@ struct flight {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::has_one(op, "airplane_id", plane, {utils::cascade_type::ALL, utils::fetch_type::EAGER});
field::has_one(op, "airplane_id", plane, {utils::cascade_type::ALL, fetch_type::EAGER});
field::attribute(op, "pilot_name", pilot_name, 255);
}
};
+2
View File
@@ -18,6 +18,8 @@ size_t test_result_reader::start_column_index() const {
return 0;
}
void test_result_reader::unshift() {}
void test_result_reader::read_value(const char *id, const size_t index, int8_t &value) {
value = -8;
}
+1
View File
@@ -38,6 +38,7 @@ public:
[[nodiscard]] const char *column(size_t index) const override;
[[nodiscard]] utils::result<bool, utils::error> fetch() override;
[[nodiscard]] size_t start_column_index() const override;
void unshift() override;
void read_value(const char *id, size_t index, int8_t &value) override;
void read_value(const char *id, size_t index, int16_t &value) override;
+1 -1
View File
@@ -37,7 +37,7 @@ TEST_CASE("Test field", "[field]") {
REQUIRE(bool_val.has_value());
REQUIRE(bool_val.value());
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, 0, 1);
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, sql::field_type::Attribute, 0, 1);
REQUIRE(f.index() == 1);
REQUIRE(!f.is_null());
REQUIRE(!f.is_integer());