progress on combining foreign_node_completer and relation_completer
This commit is contained in:
@@ -8,11 +8,12 @@
|
||||
#include "matador/orm/schema.hpp"
|
||||
|
||||
#include "../models/department.hpp"
|
||||
#include "../models/recipe.hpp"
|
||||
|
||||
using namespace matador;
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema]") {
|
||||
TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema][one-to-many]") {
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
|
||||
@@ -34,3 +35,26 @@ TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema]") {
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(!exists_result.value());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SchemaFixture, "Test schema many-to-many", "[schema][many-to-many]") {
|
||||
using namespace matador::test;
|
||||
orm::schema repo(pool/*, "NoopSchema"*/);
|
||||
|
||||
auto result = repo.attach<recipe>("recipes")
|
||||
.and_then( [&repo] { return repo.attach<ingredient>("ingredients"); } );
|
||||
REQUIRE(result);
|
||||
|
||||
result = repo.create();
|
||||
REQUIRE(result);
|
||||
|
||||
auto exists_result = repo.table_exists("recipes");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(exists_result.value());
|
||||
|
||||
result = repo.drop();
|
||||
REQUIRE(result);
|
||||
|
||||
exists_result = repo.table_exists("recipes");
|
||||
REQUIRE(exists_result.is_ok());
|
||||
REQUIRE(!exists_result.value());
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "../../models/department.hpp"
|
||||
#include "../../models/recipe.hpp"
|
||||
|
||||
struct node {};
|
||||
|
||||
@@ -30,50 +31,51 @@ struct names {
|
||||
};
|
||||
|
||||
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
|
||||
const object::repository tree;
|
||||
const object::repository repo;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
REQUIRE( repo.empty() );
|
||||
}
|
||||
|
||||
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
|
||||
object::repository tree;
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
REQUIRE( repo.empty() );
|
||||
|
||||
auto res = tree.attach<person>("person");
|
||||
auto res = repo.attach<person>("person");
|
||||
REQUIRE( res.is_ok() );
|
||||
res = tree.attach<student, person>("student");
|
||||
res = repo.attach<student, person>("student");
|
||||
REQUIRE( res.is_ok() );
|
||||
res = tree.attach<teacher, person>("teacher");
|
||||
res = repo.attach<teacher, person>("teacher");
|
||||
REQUIRE( res.is_ok() );
|
||||
|
||||
REQUIRE( !tree.empty() );
|
||||
REQUIRE( tree.size() == 3 );
|
||||
REQUIRE( !repo.empty() );
|
||||
REQUIRE( repo.size() == 3 );
|
||||
}
|
||||
|
||||
TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") {
|
||||
object::repository tree;
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
REQUIRE( repo.empty() );
|
||||
|
||||
auto res = tree.attach<person>("person");
|
||||
auto res = repo.attach<person>("person");
|
||||
REQUIRE( res.is_ok() );
|
||||
|
||||
REQUIRE( tree.size() == 1 );
|
||||
REQUIRE( repo.size() == 1 );
|
||||
|
||||
auto it = tree.begin();
|
||||
auto it = repo.begin();
|
||||
REQUIRE( it->name() == "person" );
|
||||
REQUIRE( (--it)->name() == "person" );
|
||||
REQUIRE( ++it == tree.end() );
|
||||
REQUIRE( ++it == repo.end() );
|
||||
}
|
||||
|
||||
TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") {
|
||||
object::repository tree;
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
REQUIRE( repo.empty() );
|
||||
|
||||
auto res = tree.attach<test::department>("department");
|
||||
auto res = repo.attach<test::department>("department");
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(repo.size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") {
|
||||
@@ -83,4 +85,32 @@ TEST_CASE("Test automatic creating of a relation table with values", "[schema][r
|
||||
|
||||
auto res = repo.attach<names>("names");
|
||||
REQUIRE( res.is_ok() );
|
||||
}
|
||||
|
||||
TEST_CASE("Test one to many", "[relation][one-to-many]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE( repo.empty() );
|
||||
|
||||
auto res = repo.attach<test::department>("departments")
|
||||
.and_then( [&repo] { return repo.attach<test::employee>("employees"); } );
|
||||
REQUIRE( res.is_ok() );
|
||||
REQUIRE(repo.size() == 2);
|
||||
REQUIRE(repo.contains("departments"));
|
||||
REQUIRE(repo.contains("employees"));
|
||||
}
|
||||
|
||||
TEST_CASE("Test many to many relation", "[relation][many-to-many]") {
|
||||
object::repository repo;
|
||||
|
||||
REQUIRE(repo.empty());
|
||||
|
||||
auto result = repo.attach<test::recipe>("recipes")
|
||||
.and_then( [&repo] { return repo.attach<test::ingredient>("ingredients"); } );
|
||||
REQUIRE(result);
|
||||
|
||||
REQUIRE(repo.size() == 3);
|
||||
REQUIRE(repo.contains("ingredients"));
|
||||
REQUIRE(repo.contains("recipes"));
|
||||
REQUIRE(repo.contains("recipe_ingredients"));
|
||||
}
|
||||
@@ -21,8 +21,8 @@ struct order_details
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "order_details_id", order_details_id);
|
||||
field::belongs_to(op, "order_id", order_, utils::default_foreign_attributes);
|
||||
field::has_one(op, "product_id", product_, utils::default_foreign_attributes);
|
||||
field::belongs_to(op, "order_id", order_, utils::CascadeNoneFetchLazy);
|
||||
field::has_one(op, "product_id", product_, utils::CascadeNoneFetchLazy);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user