added belongs to and has one tests
This commit is contained in:
@@ -30,6 +30,10 @@ struct ingredient_pk_generator {
|
||||
: name(std::move(name)) {
|
||||
}
|
||||
|
||||
ingredient_pk_generator(std::string name, std::vector<object_ptr<recipe_pk_generator<PkAttribute>>> recps)
|
||||
: name(std::move(name))
|
||||
, recipes(std::move(recps)){}
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
@@ -51,8 +55,7 @@ struct recipe_pk_generator {
|
||||
}
|
||||
recipe_pk_generator(std::string name, std::vector<object_ptr<ingredient_pk_generator<PkAttribute>>> ings)
|
||||
: name(std::move(name))
|
||||
, ingredients(std::move(ings)){
|
||||
}
|
||||
, ingredients(std::move(ings)){}
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
@@ -218,3 +221,43 @@ TEST_CASE_METHOD(SessionFixture, "Test insert object with has many to many relat
|
||||
REQUIRE(ing_result.is_ok());
|
||||
REQUIRE(ing_result.value()->recipes.size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Test insert object with has many to many relation sequence reverse", "[session][insert][sequence][has_many_to_many][reverse]") {
|
||||
auto result = schema.attach<recipe_sequence>("recipes")
|
||||
.and_then( [this] { return schema.attach<ingredient_sequence>("ingredients"); } )
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
|
||||
query::session ses({bus, connection::dns, 4}, schema);
|
||||
|
||||
std::vector recipes {
|
||||
make_object<recipe_sequence>("Apple Pie"),
|
||||
make_object<recipe_sequence>("Strawberry Cake"),
|
||||
make_object<recipe_sequence>("Pineapple Pie")
|
||||
};
|
||||
|
||||
std::vector ingredients {
|
||||
make_object<ingredient_sequence>("Apple", std::vector{recipes[0], recipes[2]}),
|
||||
make_object<ingredient_sequence>("Strawberry", std::vector{recipes[2]}),
|
||||
make_object<ingredient_sequence>("Pineapple", std::vector{recipes[2]}),
|
||||
make_object<ingredient_sequence>("Sugar", std::vector{recipes[0]}),
|
||||
make_object<ingredient_sequence>("Flour", std::vector{recipes[0]}),
|
||||
make_object<ingredient_sequence>("Butter", std::vector{recipes[1]}),
|
||||
make_object<ingredient_sequence>("Beans", std::vector{recipes[1]})
|
||||
};
|
||||
|
||||
for (auto &i: ingredients) {
|
||||
REQUIRE(i.is_transient());
|
||||
auto res = ses.insert(i);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->is_persistent());
|
||||
}
|
||||
|
||||
auto recipe_result = ses.find<ingredient_sequence>(1);
|
||||
REQUIRE(recipe_result.is_ok());
|
||||
REQUIRE(recipe_result->is_persistent());
|
||||
REQUIRE(recipe_result.value()->recipes.size() == 2);
|
||||
|
||||
const auto ing_result = ses.find<recipe_sequence>(recipes[0]->id);
|
||||
REQUIRE(ing_result.is_ok());
|
||||
REQUIRE(ing_result.value()->ingredients.size() == 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user