added has_one eager functionality and tests
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "../../models/order.hpp"
|
||||
#include "../../models/student.hpp"
|
||||
#include "../../models/user.hpp"
|
||||
#include "../../models/country.hpp"
|
||||
#include "../../models/model_metas.hpp"
|
||||
|
||||
using namespace matador::object;
|
||||
@@ -386,7 +387,7 @@ TEST_CASE("Test eager relationship", "[query][entity][builder]") {
|
||||
// std::cout << ctx << std::endl;
|
||||
}
|
||||
|
||||
TEST_CASE("Test has one relationship", "[query][entity][builder][has_one]") {
|
||||
TEST_CASE("Test has one lazy relationship", "[query][entity][builder][has_one][lazy]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
@@ -401,5 +402,27 @@ TEST_CASE("Test has one relationship", "[query][entity][builder][has_one]") {
|
||||
auto q = eqb.build<user>();
|
||||
REQUIRE(q.is_ok());
|
||||
const auto sql = q->str(db);
|
||||
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."name", "t01"."password" FROM "users" "t01" ORDER BY "t01"."id" ASC)";
|
||||
|
||||
REQUIRE(expected_sql == sql);
|
||||
}
|
||||
|
||||
TEST_CASE("Test has one eager relationship", "[query][entity][builder][has_one][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;
|
||||
auto result = scm.attach<country>("countries")
|
||||
.and_then( [&scm] { return scm.attach<capital>("capitals"); } );
|
||||
REQUIRE(result);
|
||||
|
||||
select_query_builder eqb(scm);
|
||||
|
||||
auto q = eqb.build<country>();
|
||||
REQUIRE(q.is_ok());
|
||||
const auto sql = q->str(db);
|
||||
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."name", "t02"."id", "t02"."name", "t02"."country_id" FROM "countries" "t01" LEFT JOIN "capitals" "t02" ON "t01"."id" = "t02"."country_id" ORDER BY "t01"."id" ASC)";
|
||||
|
||||
REQUIRE(expected_sql == sql);
|
||||
}
|
||||
Reference in New Issue
Block a user