added belongs to many eager test loading via sql join (progress)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "models/airplane.hpp"
|
||||
#include "models/author.hpp"
|
||||
#include "models/book.hpp"
|
||||
#include "models/department.hpp"
|
||||
#include "models/flight.hpp"
|
||||
|
||||
#include <iostream>
|
||||
@@ -94,7 +95,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][f
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-many relation", "[session][find][one-to-many]") {
|
||||
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-many lazy relation", "[session][find][one-to-many][eager]") {
|
||||
auto result = ses.attach<author>("authors")
|
||||
.and_then( [this] { return ses.attach<book>("books"); } )
|
||||
.and_then( [this] { return ses.create_schema(); } );
|
||||
@@ -145,4 +146,57 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
|
||||
for (auto it = all_authors.begin(); it != all_authors.end(); ++it) {
|
||||
std::cout << "author: " << it->first_name << " (books: " << it->books.size() << ")\n";
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-many eager relation", "[session][find][one-to-many][eager]") {
|
||||
auto result = ses.attach<department>("departments")
|
||||
.and_then( [this] { return ses.attach<employee>("employees"); } )
|
||||
.and_then( [this] { return ses.create_schema(); } );
|
||||
|
||||
tables_to_drop.emplace("departments");
|
||||
tables_to_drop.emplace("employees");
|
||||
|
||||
std::vector<std::unique_ptr<department>> departments;
|
||||
departments.emplace_back(new department{1, "Insurance", {}});
|
||||
departments.emplace_back(new department{ 2, "Invoice", {}});
|
||||
|
||||
for (auto &&a: departments) {
|
||||
auto res = ses.insert(a.release());
|
||||
REQUIRE(res.is_ok());
|
||||
}
|
||||
|
||||
auto find_result = ses.find<department>();
|
||||
REQUIRE(find_result.is_ok());
|
||||
auto all_departments = find_result.release();
|
||||
std::vector<object_ptr<department>> departments_repo;
|
||||
for (auto it = all_departments.begin(); it != all_departments.end(); ++it) {
|
||||
std::cout << "author: " << it->name << " (employees: " << it->employees.size() << ")\n";
|
||||
departments_repo.emplace_back(it.release());
|
||||
}
|
||||
REQUIRE(departments_repo.size() == 2);
|
||||
|
||||
std::vector<std::unique_ptr<employee>> employees;
|
||||
employees.emplace_back( new employee{3, "George", "Orwell", departments_repo[0]} );
|
||||
employees.emplace_back( new employee{4, "Chris", "Tucker", departments_repo[0]} );
|
||||
employees.emplace_back( new employee{5, "Steven", "King", departments_repo[0]} );
|
||||
employees.emplace_back( new employee{6, "John", "Wayne", departments_repo[0]} );
|
||||
employees.emplace_back( new employee{7, "Clint", "Eastwood", departments_repo[0]} );
|
||||
employees.emplace_back( new employee{8, "Emma", "Thompson", departments_repo[1]} );
|
||||
employees.emplace_back( new employee{9, "Ed", "Wood", departments_repo[1]} );
|
||||
employees.emplace_back( new employee{10, "Steven", "Spielberg", departments_repo[1]} );
|
||||
employees.emplace_back( new employee{11, "Jane", "Fonda", departments_repo[1]} );
|
||||
employees.emplace_back( new employee{12, "Julia", "Roberts", departments_repo[1]} );
|
||||
|
||||
for (auto &&b: employees) {
|
||||
auto res = ses.insert(b.release());
|
||||
REQUIRE(res.is_ok());
|
||||
}
|
||||
|
||||
find_result = ses.find<department>();
|
||||
REQUIRE(find_result);
|
||||
|
||||
all_departments = find_result.release();
|
||||
for (auto it = all_departments.begin(); it != all_departments.end(); ++it) {
|
||||
std::cout << "author: " << it->name << " (employees: " << it->employees.size() << ")\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user