diff --git a/test/models/author.hpp b/test/models/author.hpp index 7a7f583..1c8b892 100644 --- a/test/models/author.hpp +++ b/test/models/author.hpp @@ -15,6 +15,7 @@ struct author std::string date_of_birth; unsigned short year_of_birth{}; bool distinguished{false}; + std::vector> books; template void process(Operator &op) @@ -26,6 +27,7 @@ struct author field::attribute(op, "date_of_birth", date_of_birth, 31); field::attribute(op, "year_of_birth", year_of_birth); field::attribute(op, "distinguished", distinguished); + field::has_many(op, "books", books, "author_id", "id", utils::fetch_type::LAZY); } }; diff --git a/test/models/book.hpp b/test/models/book.hpp index a3e7401..2e645b8 100644 --- a/test/models/book.hpp +++ b/test/models/book.hpp @@ -25,7 +25,7 @@ struct book namespace field = matador::utils::access; field::primary_key(op, "id", id); 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); } }; diff --git a/test/models/recipe.hpp b/test/models/recipe.hpp index b4087e2..fd6e310 100644 --- a/test/models/recipe.hpp +++ b/test/models/recipe.hpp @@ -11,16 +11,19 @@ namespace matador::test { +struct recipe; struct ingredient { unsigned long id{}; std::string name; + std::vector> recipes; template void process(Operator &op) { namespace field = matador::utils::access; field::primary_key(op, "id", id); 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{}; std::string name; + std::vector> ingredients; template void process(Operator &op) { namespace field = matador::utils::access; field::primary_key(op, "id", id); field::attribute(op, "name", name, 255); + field::has_many(op, "ingredients", ingredients, "recipe_id", "ingredient_id", utils::fetch_type::EAGER); } };