fixed has many and belongs to eager loading via sql join
This commit is contained in:
@@ -126,10 +126,10 @@ const class sql::dialect &session::dialect() const
|
||||
|
||||
query::fetchable_query session::build_select_query(entity_query_data &&data) {
|
||||
return query::query::select(data.columns)
|
||||
.from(data.root_table_name)
|
||||
.from(*data.root_table)
|
||||
.join_left(data.joins)
|
||||
.where(std::move(data.where_clause))
|
||||
.order_by(sql::column{data.root_table_name, data.pk_column_})
|
||||
.order_by(sql::column{data.root_table, data.pk_column_name})
|
||||
.asc();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,39 +3,42 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace matador::orm {
|
||||
|
||||
void session_query_builder::on_primary_key(const char *id, std::string &, size_t)
|
||||
{
|
||||
push(id);
|
||||
if (!is_root_entity()) {
|
||||
const auto b = pk_.is_varchar();
|
||||
std::cout << "is matching primary key: " << std::boolalpha << b << "\n";
|
||||
}
|
||||
void session_query_builder::on_primary_key(const char *id, std::string &, size_t) {
|
||||
push(id);
|
||||
if (!is_root_entity()) {
|
||||
const auto b = pk_.is_varchar();
|
||||
std::cout << "is matching primary key: " << std::boolalpha << b << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void session_query_builder::on_revision(const char *id, unsigned long long &/*rev*/)
|
||||
{
|
||||
push(id);
|
||||
void session_query_builder::on_revision(const char *id, unsigned long long &/*rev*/) {
|
||||
push(id);
|
||||
}
|
||||
|
||||
void session_query_builder::push(const std::string &column_name)
|
||||
{
|
||||
char str[4];
|
||||
snprintf(str, 4, "c%02d", ++column_index);
|
||||
entity_query_data_.columns.emplace_back(table_info_stack_.top().get().name(), column_name, str);
|
||||
void session_query_builder::push(const std::string &column_name) {
|
||||
const auto it = processed_tables_.find(table_info_stack_.top().get().name());
|
||||
if (it == processed_tables_.end()) {
|
||||
throw query_builder_exception{query_build_error::UnexpectedError};
|
||||
}
|
||||
entity_query_data_.columns.emplace_back(it->second, column_name, build_alias('c', ++column_index));
|
||||
}
|
||||
|
||||
std::string session_query_builder::build_alias(const char prefix, const unsigned int count) {
|
||||
char str[4];
|
||||
snprintf(str, 4, "%c%02d", prefix, count);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool session_query_builder::is_root_entity() const {
|
||||
return table_info_stack_.size() == 1;
|
||||
return table_info_stack_.size() == 1;
|
||||
}
|
||||
|
||||
void session_query_builder::append_join(const sql::column &left, const sql::column &right)
|
||||
{
|
||||
using namespace matador::query;
|
||||
entity_query_data_.joins.push_back({
|
||||
{ right.table_ },
|
||||
make_condition(left == right)
|
||||
});
|
||||
void session_query_builder::append_join(const sql::column &left, const sql::column &right) {
|
||||
using namespace matador::query;
|
||||
entity_query_data_.joins.push_back({
|
||||
{right.table_},
|
||||
make_condition(left == right)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user