added belongs-to-eager test
This commit is contained in:
+16
-15
@@ -10,51 +10,52 @@
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct recipe;
|
||||
struct ingredient
|
||||
{
|
||||
|
||||
struct ingredient {
|
||||
unsigned int id{};
|
||||
std::string name;
|
||||
std::vector<object::object_ptr<recipe>> recipes{};
|
||||
std::vector<object::object_ptr<recipe> > recipes{};
|
||||
|
||||
ingredient() = default;
|
||||
|
||||
ingredient()= default;
|
||||
ingredient(const unsigned int id, std::string name)
|
||||
: id(id), name(std::move(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, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::fetch_type::Eager);
|
||||
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::CascadeAllFetchEager);
|
||||
}
|
||||
};
|
||||
|
||||
struct recipe
|
||||
{
|
||||
struct recipe {
|
||||
unsigned int id{};
|
||||
std::string name;
|
||||
std::vector<object::object_ptr<ingredient>> ingredients{};
|
||||
std::vector<object::object_ptr<ingredient> > ingredients{};
|
||||
|
||||
recipe() = default;
|
||||
|
||||
recipe()= default;
|
||||
recipe(const unsigned int id, std::string name)
|
||||
: id(id), name(std::move(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, "recipe_ingredients", ingredients, utils::fetch_type::Lazy);
|
||||
field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::CascadeAllFetchLazy);
|
||||
}
|
||||
};
|
||||
|
||||
// class recipe_ingredient : public object::many_to_many_relation<recipe, ingredient> {
|
||||
// public:
|
||||
// recipe_ingredient() : many_to_many_relation("recipe_id", "ingredient_id") {}
|
||||
// recipe_ingredient() : many_to_many_relation("recipe_id", "ingredient_id") {}
|
||||
// };
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_RECIPE_HPP
|
||||
|
||||
Reference in New Issue
Block a user