added belongs-to-eager test

This commit is contained in:
2026-01-10 18:54:18 +01:00
parent b9f5819be5
commit db8e137c11
20 changed files with 403 additions and 278 deletions
+33 -31
View File
@@ -11,52 +11,54 @@
#include <vector>
namespace matador::test {
struct course;
struct student {
unsigned int id{};
std::string name;
std::vector<object::object_ptr<course>> courses;
unsigned int id{};
std::string name;
std::vector<object::object_ptr<course> > courses;
student() = default;
explicit student(unsigned int id, std::string name)
: id(id)
, name(std::move(name)) {}
student() = default;
template < class Operator >
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::fetch_type::Lazy);
}
explicit student(unsigned int id, std::string name)
: id(id)
, name(std::move(name)) {
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::CascadeAllFetchLazy);
}
};
struct course {
unsigned int id{};
std::string title;
std::vector<object::object_ptr<student>> students;
unsigned int id{};
std::string title;
std::vector<object::object_ptr<student> > students;
course() = default;
explicit course(unsigned int id, std::string title)
: id(id)
, title(std::move(title)) {}
course() = default;
template < class Operator >
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 255);
field::has_many_to_many(op, "student_courses", students, utils::fetch_type::Eager);
}
explicit course(unsigned int id, std::string title)
: id(id)
, title(std::move(title)) {
}
template<class Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 255);
field::has_many_to_many(op, "student_courses", students, utils::CascadeAllFetchEager);
}
};
class student_course : public object::many_to_many_relation<student, course> {
public:
student_course() : many_to_many_relation("student_id", "course_id") {}
student_course() : many_to_many_relation("student_id", "course_id") {
}
};
}
#endif //QUERY_STUDENT_HPP