added has_one eager functionality and tests
This commit is contained in:
@@ -7,12 +7,13 @@
|
||||
#include "matador/query/session.hpp"
|
||||
|
||||
#include "models/user.hpp"
|
||||
#include "models/country.hpp"
|
||||
|
||||
using namespace matador::test;
|
||||
using namespace matador::query;
|
||||
using namespace matador::object;
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Test insert object with has_one relation", "[session][insert][has_one]") {
|
||||
TEST_CASE_METHOD(SessionFixture, "Test insert object with has_one relation lazy", "[session][insert][has_one][lazy]") {
|
||||
const auto result = schema.attach<user_identity>("users")
|
||||
.and_then( [this] { return schema.attach<user_session_identity>("user_sessions"); } )
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
@@ -33,4 +34,27 @@ TEST_CASE_METHOD(SessionFixture, "Test insert object with has_one relation", "[s
|
||||
REQUIRE(user_result.is_ok());
|
||||
us = user_result.value()->session;
|
||||
REQUIRE(us->session_token == "session1");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Test insert object with has_one relation eager", "[session][insert][has_one][eager]") {
|
||||
const auto result = schema.attach<country_identity>("countries")
|
||||
.and_then( [this] { return schema.attach<capital_identity>("capitals"); } )
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
session ses({bus, connection::dns, 4}, schema);
|
||||
|
||||
const auto ger = make_object<country_identity>("Germany");
|
||||
auto ger_cap = make_object<capital_identity>("Berlin", ger);
|
||||
|
||||
REQUIRE(ger.is_transient());
|
||||
REQUIRE(ger_cap.is_transient());
|
||||
REQUIRE(ses.insert(ger_cap).is_ok());
|
||||
REQUIRE(ger_cap.is_persistent());
|
||||
REQUIRE(ger.is_persistent());
|
||||
|
||||
const auto ger_result = ses.find<country_identity>(ger->id);
|
||||
REQUIRE(ger_result.is_ok());
|
||||
ger_cap = ger_result.value()->capital;
|
||||
REQUIRE(ger_cap->name == "Berlin");
|
||||
}
|
||||
Reference in New Issue
Block a user