started lazy loading

This commit is contained in:
Sascha Kühl 2025-08-18 07:37:23 +02:00
parent 2fdbfc651e
commit 466977b620
1 changed files with 14 additions and 6 deletions

View File

@ -4,7 +4,7 @@
#include "matador/orm/query_builder_exception.hpp" #include "matador/orm/query_builder_exception.hpp"
#include "matador/query/condition.hpp" #include "matador/query/condition.hpp"
#include "matador/query/query_intermediates.hpp" #include "matador/query/query.hpp"
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"
@ -254,17 +254,18 @@ private:
template<class Pointer> template<class Pointer>
void session_query_builder::on_foreign_object(const char *id, Pointer &, const utils::foreign_attributes &attr) { void session_query_builder::on_foreign_object(const char *id, Pointer &, const utils::foreign_attributes &attr) {
const auto info = schema_.info<typename Pointer::value_type>();
if (!info) {
throw query_builder_exception{query_build_error::UnknownType};
}
const auto foreign_table = std::make_shared<sql::table>(info->get().name(), build_alias('t', ++table_index));
if (attr.fetch() == utils::fetch_type::EAGER) { if (attr.fetch() == utils::fetch_type::EAGER) {
const auto info = schema_.info<typename Pointer::value_type>();
if (!info) {
throw query_builder_exception{query_build_error::UnknownType};
}
auto next = processed_tables_.find(info->get().name()); auto next = processed_tables_.find(info->get().name());
if (next != processed_tables_.end()) { if (next != processed_tables_.end()) {
return; return;
} }
table_info_stack_.push({info.value(), std::make_shared<sql::table>(info->get().name(), build_alias('t', ++table_index))}); table_info_stack_.push({info.value(), foreign_table});
next = processed_tables_.insert({info->get().name(), table_info_stack_.top().table}).first; next = processed_tables_.insert({info->get().name(), table_info_stack_.top().table}).first;
typename Pointer::value_type obj; typename Pointer::value_type obj;
access::process(*this, obj); access::process(*this, obj);
@ -279,7 +280,14 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
sql::column{next->second, pk->name()} sql::column{next->second, pk->name()}
); );
} else { } else {
// using namespace matador::utils;
// using namespace matador::query;
push(id); push(id);
// create select query
// const auto result = matador::query::query::select<typename Pointer::value_type>(schema_)
// .from(*foreign_table)
// .where(sql::column(foreign_table, id, "") == _)
// .prepare();
} }
} }