implemented lazy loading for object_ptr and belongs_to

This commit is contained in:
2026-01-15 12:40:54 +01:00
parent db8e137c11
commit 7626331866
81 changed files with 1790 additions and 927 deletions
+7
View File
@@ -12,6 +12,13 @@ namespace matador::test {
struct book;
struct author {
author() = default;
author(const unsigned int id, std::string first_name, std::string last_name, std::string date_of_birth, const unsigned short year_of_birth, const bool distinguished)
: id(id), first_name(std::move(first_name))
, last_name(std::move(last_name))
, date_of_birth(std::move(date_of_birth))
, year_of_birth(year_of_birth)
, distinguished(distinguished) {}
unsigned int id{};
std::string first_name;
std::string last_name;
+3
View File
@@ -12,6 +12,9 @@ namespace matador::test {
struct author;
struct book {
book() = default;
book(const unsigned int id, std::string title, object::object_ptr<author> author, unsigned short published_in)
: id(id), title(std::move(title)), book_author(std::move(author)), published_in(published_in) {}
unsigned int id{};
std::string title;
object::object_ptr<author> book_author;
+6
View File
@@ -11,6 +11,9 @@ namespace matador::test {
struct employee;
struct department {
department() = default;
department(const unsigned int id, std::string name)
: id(id), name(std::move(name)) {}
unsigned int id{};
std::string name;
std::vector<object::object_ptr<employee>> employees{};
@@ -27,6 +30,9 @@ struct department {
};
struct employee {
employee() = default;
employee(const unsigned int id, std::string first, std::string last, object::object_ptr<department> dep)
: id(id), first_name(std::move(first)), last_name(std::move(last)), dep(std::move(dep)) {}
unsigned int id{};
std::string first_name;
std::string last_name;
+4 -5
View File
@@ -5,7 +5,6 @@
#include "supplier.hpp"
#include "matador/utils/access.hpp"
#include "matador/utils/cascade_type.hpp"
#include "matador/object/object_ptr.hpp"
@@ -14,8 +13,8 @@
namespace matador::test {
struct product {
std::string product_name;
object::object_ptr<supplier> supplier;
object::object_ptr<category> category;
object::object_ptr<supplier> seller;
object::object_ptr<category> type;
std::string quantity_per_unit;
unsigned int unit_price;
unsigned int units_in_stock;
@@ -28,8 +27,8 @@ struct product {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "product_name", product_name, 255);
field::belongs_to(op, "supplier_id", supplier, CascadeAllFetchLazy);
field::belongs_to(op, "category_id", category, CascadeAllFetchLazy);
field::belongs_to(op, "supplier_id", seller, CascadeAllFetchLazy);
field::belongs_to(op, "category_id", type, CascadeAllFetchLazy);
field::attribute(op, "quantity_per_unit", quantity_per_unit, 255);
field::attribute(op, "unit_price", unit_price);
field::attribute(op, "units_in_stock", units_in_stock);
+8
View File
@@ -13,6 +13,10 @@ namespace matador::test {
struct package;
struct shipment {
shipment() = default;
shipment(const long id, std::string tracking_number)
: id(id), tracking_number(std::move(tracking_number)) {}
long id{};
std::string tracking_number;
object::collection<object::object_ptr<package> > packages{};
@@ -27,6 +31,10 @@ struct shipment {
};
struct package {
package() = default;
package(const long id, double weight, object::object_ptr<shipment> del)
: id(id), weight(weight), delivery(std::move(del)){}
long id{};
double weight{};
object::object_ptr<shipment> delivery;