query/test/models/student.hpp

65 lines
1.5 KiB
C++

#ifndef QUERY_STUDENT_HPP
#define QUERY_STUDENT_HPP
#include "matador/utils/access.hpp"
#include "matador/utils/foreign_attributes.hpp"
#include "matador/object/object_ptr.hpp"
#include "matador/object/many_to_many_relation.hpp"
#include <utility>
#include <vector>
namespace matador::test {
struct course;
struct student {
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)) {
}
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;
course() = default;
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") {
}
};
}
#endif //QUERY_STUDENT_HPP