added to many fields to entities author, book, recipe and ingredient

This commit is contained in:
Sascha Kuehl 2024-03-29 11:41:14 +01:00
parent 05c0c0393d
commit 6f3e589e10
3 changed files with 8 additions and 1 deletions

View File

@ -15,6 +15,7 @@ struct author
std::string date_of_birth; std::string date_of_birth;
unsigned short year_of_birth{}; unsigned short year_of_birth{};
bool distinguished{false}; bool distinguished{false};
std::vector<matador::sql::entity<book>> books;
template<typename Operator> template<typename Operator>
void process(Operator &op) void process(Operator &op)
@ -26,6 +27,7 @@ struct author
field::attribute(op, "date_of_birth", date_of_birth, 31); field::attribute(op, "date_of_birth", date_of_birth, 31);
field::attribute(op, "year_of_birth", year_of_birth); field::attribute(op, "year_of_birth", year_of_birth);
field::attribute(op, "distinguished", distinguished); field::attribute(op, "distinguished", distinguished);
field::has_many(op, "books", books, "author_id", "id", utils::fetch_type::LAZY);
} }
}; };

View File

@ -25,7 +25,7 @@ struct book
namespace field = matador::utils::access; namespace field = matador::utils::access;
field::primary_key(op, "id", id); field::primary_key(op, "id", id);
field::attribute(op, "title", title, 511); field::attribute(op, "title", title, 511);
field::has_one(op, "author_id", book_author, utils::fetch_type::EAGER); field::belongs_to(op, "author_id", book_author, utils::fetch_type::EAGER);
field::attribute(op, "published_in", published_in); field::attribute(op, "published_in", published_in);
} }
}; };

View File

@ -11,16 +11,19 @@
namespace matador::test { namespace matador::test {
struct recipe;
struct ingredient struct ingredient
{ {
unsigned long id{}; unsigned long id{};
std::string name; std::string name;
std::vector<matador::sql::entity<recipe>> recipes;
template<class Operator> template<class Operator>
void process(Operator &op) { void process(Operator &op) {
namespace field = matador::utils::access; namespace field = matador::utils::access;
field::primary_key(op, "id", id); field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255); field::attribute(op, "name", name, 255);
field::has_many(op, "recipes", recipes, "ingredient_id", "recipe_id", utils::fetch_type::EAGER);
} }
}; };
@ -28,12 +31,14 @@ struct recipe
{ {
unsigned long id{}; unsigned long id{};
std::string name; std::string name;
std::vector<matador::sql::entity<ingredient>> ingredients;
template<class Operator> template<class Operator>
void process(Operator &op) { void process(Operator &op) {
namespace field = matador::utils::access; namespace field = matador::utils::access;
field::primary_key(op, "id", id); field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255); field::attribute(op, "name", name, 255);
field::has_many(op, "ingredients", ingredients, "recipe_id", "ingredient_id", utils::fetch_type::EAGER);
} }
}; };