48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#ifndef DEPARTMENT_EMPLOYEE_HPP
|
|
#define DEPARTMENT_EMPLOYEE_HPP
|
|
|
|
#include "matador/object/object_ptr.hpp"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace matador::test {
|
|
|
|
struct employee;
|
|
|
|
struct department {
|
|
unsigned int id{};
|
|
std::string name;
|
|
std::vector<object::object_ptr<employee>> employees;
|
|
object::object_ptr<employee> manager;
|
|
|
|
template<typename Operator>
|
|
void process(Operator &op) {
|
|
namespace field = matador::access;
|
|
field::primary_key(op, "id", id);
|
|
field::attribute(op, "name", name, 63);
|
|
field::has_many(op, "employees", employees, "dep_id", utils::fetch_type::EAGER);
|
|
field::belongs_to(op, "manager_id", manager, utils::fetch_type::EAGER);
|
|
}
|
|
};
|
|
|
|
struct employee {
|
|
unsigned int id{};
|
|
std::string first_name;
|
|
std::string last_name;
|
|
object::object_ptr<department> dep;
|
|
|
|
template<typename Operator>
|
|
void process(Operator &op) {
|
|
namespace field = matador::access;
|
|
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);
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif //DEPARTMENT_EMPLOYEE_HPP
|