fixed table aliases
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "../../models/airplane.hpp"
|
||||
#include "../../models/author.hpp"
|
||||
#include "../../models/department.hpp"
|
||||
#include "../../models/book.hpp"
|
||||
#include "../../models/flight.hpp"
|
||||
#include "../../models/recipe.hpp"
|
||||
@@ -29,6 +30,7 @@ using namespace matador::test;
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager has one", "[query][entity][builder]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
auto result = scm.attach<airplane>("airplanes")
|
||||
@@ -133,6 +135,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager has many belongs to", "[query][entity][builder]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
auto result = scm.attach<product>("products")
|
||||
@@ -190,6 +193,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager many to many", "[query][entity][builder]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
auto result = scm.attach<recipe>("recipes")
|
||||
@@ -215,8 +219,8 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> expected_join_data {
|
||||
{ "recipe_ingredients", R"("t01"."id" = "recipe_ingredients"."ingredient_id")"},
|
||||
{ "recipes", R"("t02"."recipe_id" = "recipes"."id")"}
|
||||
{ "recipe_ingredients", R"("t01"."id" = "t02"."ingredient_id")"},
|
||||
{ "recipes", R"("t02"."recipe_id" = "t03"."id")"}
|
||||
};
|
||||
|
||||
query_context qc;
|
||||
@@ -234,6 +238,7 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager many to many (inverse part)", "[query][entity][builder]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
auto result = scm.attach<student>("students")
|
||||
@@ -259,8 +264,8 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> expected_join_data {
|
||||
{ "student_courses", R"("courses"."id" = "student_courses"."course_id")"},
|
||||
{ "students", R"("student_courses"."student_id" = "students"."id")"}
|
||||
{ "student_courses", R"("t01"."id" = "t02"."course_id")"},
|
||||
{ "students", R"("t02"."student_id" = "t03"."id")"}
|
||||
};
|
||||
|
||||
query_context qc;
|
||||
@@ -276,53 +281,17 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
|
||||
REQUIRE(cond == R"("courses"."id" = 17)");
|
||||
}
|
||||
|
||||
namespace matador::test::orm {
|
||||
|
||||
struct employee;
|
||||
|
||||
struct department {
|
||||
unsigned int id{};
|
||||
std::string name;
|
||||
std::vector<object_ptr<employee>> employees;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 63);
|
||||
field::has_many(op, "employees", employees, "dep_id", utils::fetch_type::EAGER);
|
||||
}
|
||||
};
|
||||
|
||||
struct employee {
|
||||
unsigned int id{};
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
object_ptr<department> dep;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "first_name", first_name, 63);
|
||||
field::attribute(op, "last_name", last_name, 63);
|
||||
field::belongs_to(op, "dep_id", dep, utils::fetch_type::EAGER);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Test eager relationship", "[session][eager]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
auto result = scm.attach<orm::department>("departments")
|
||||
.and_then( [&scm] { return scm.attach<orm::employee>("employees"); } );
|
||||
auto result = scm.attach<department>("departments")
|
||||
.and_then( [&scm] { return scm.attach<employee>("employees"); } );
|
||||
|
||||
session_query_builder eqb(scm);
|
||||
|
||||
auto data = eqb.build<orm::department>();
|
||||
auto data = eqb.build<department>();
|
||||
REQUIRE(data.is_ok());
|
||||
|
||||
auto ctx = query::select(data->columns)
|
||||
|
||||
Reference in New Issue
Block a user