#ifndef QUERY_RECIPE_HPP #define QUERY_RECIPE_HPP #include "matador/utils/access.hpp" #include "matador/utils/foreign_attributes.hpp" #include "matador/object/object_ptr.hpp" #include "matador/object/collection.hpp" #include "matador/object/many_to_many_relation.hpp" #include #include namespace matador::test { struct recipe; struct ingredient { unsigned int id{}; std::string name; object::collection > recipes{}; ingredient() = default; ingredient(const unsigned int id, std::string name) : id(id), name(std::move(name)) { } template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id); field::attribute(op, "name", name, UniqueVarChar255); field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager); } }; struct recipe { unsigned int id{}; std::string name; object::collection > ingredients{}; recipe() = default; recipe(const unsigned int id, std::string name) : id(id), name(std::move(name)) { } recipe(const unsigned int id, std::string name, std::vector> ings) : id(id) , name(std::move(name)) , ingredients(std::move(ings)){ } template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id); field::attribute(op, "name", name, UniqueVarChar255); field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy); } }; template struct recipe_pk_generator; template struct ingredient_pk_generator { unsigned int id{}; std::string name; object::collection>> recipes{}; ingredient_pk_generator() = default; explicit ingredient_pk_generator(std::string name) : name(std::move(name)) { } ingredient_pk_generator(std::string name, std::vector>> recps) : name(std::move(name)) , recipes(std::move(recps)){} template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id, PkAttribute); field::attribute(op, "name", name, UniqueVarChar255); field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager); } }; template struct recipe_pk_generator { unsigned int id{}; std::string name; object::collection>> ingredients{}; recipe_pk_generator() = default; explicit recipe_pk_generator(std::string name) : name(std::move(name)) { } recipe_pk_generator(std::string name, std::vector>> ings) : name(std::move(name)) , ingredients(std::move(ings)){} template void process(Operator &op) { namespace field = matador::access; field::primary_key(op, "id", id, PkAttribute); field::attribute(op, "name", name, UniqueVarChar255); field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy); } }; using ingredient_identity = ingredient_pk_generator; using ingredient_table = ingredient_pk_generator; using ingredient_sequence = ingredient_pk_generator; using recipe_identity = recipe_pk_generator; using recipe_table = recipe_pk_generator; using recipe_sequence = recipe_pk_generator; } #endif //QUERY_RECIPE_HPP