added has_many for non object_ptr types

This commit is contained in:
Sascha Kühl
2026-01-16 15:54:21 +01:00
parent 5dae396842
commit 4c899ae2f2
8 changed files with 39 additions and 52 deletions
+8 -4
View File
@@ -83,12 +83,12 @@ public:
on_foreign_key(id, x, attr);
}
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &attr) {
template<class CollectionType>
void on_has_many(const char * /*id*/, CollectionType &, const char *, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
return;
}
const auto it = repo_.find(typeid(typename ContainerType::value_type::value_type));
const auto it = repo_.find(typeid(typename CollectionType::value_type::value_type));
if (it == repo_.end()) {
// Todo: throw exception
return;
@@ -97,13 +97,17 @@ public:
if (seen_tables.count(it->second.name()) == 0) {
const auto itt = seen_tables.insert(it->second.name()).first;
table_stack_.push(&it->second.table());
typename ContainerType::value_type::value_type obj;
typename CollectionType::value_type::value_type obj;
access::process(*this, obj);
table_stack_.pop();
seen_tables.erase(itt);
}
}
template<class CollectionType>
void on_has_many(const char * /*id*/, CollectionType &, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
}
template<class ContainerType>
void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char *join_column, const char *inverse_join_column, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
+7 -29
View File
@@ -114,13 +114,13 @@ public:
void operator()(const T*) const {}
};
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
template<class CollectionType>
void on_has_many(const char * /*id*/, CollectionType &, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
if (attr.fetch() != utils::fetch_type::Eager) {
return;
}
const auto it = schema_.find(typeid(typename ContainerType::value_type::value_type));
const auto it = schema_.find(typeid(typename CollectionType::value_type::value_type));
if (it == schema_.end()) {
throw query_builder_exception{query_build_error::UnknownType};
}
@@ -133,7 +133,7 @@ public:
table_info_stack_.push({it->second.node().info(), it->second.table().as(build_alias('t', ++table_index))});
next = processed_tables_.insert({it->second.name(), table_info_stack_.top().table}).first;
typename ContainerType::value_type::value_type obj;
typename CollectionType::value_type::value_type obj;
access::process(*this , obj);
table_info_stack_.pop();
@@ -145,32 +145,10 @@ public:
table_column{&table_info_stack_.top().table, table_info_stack_.top().info.primary_key_attribute()->name()},
table_column{&next->second, join_column}
);
}
// const auto result = schema_.repo().basic_info(typeid(typename ContainerType::value_type::value_type));
// if (!result) {
// throw query_builder_exception{query_build_error::UnknownType};
// }
//
// const auto &info = result.value().get();
// auto next = processed_tables_.find(info.name());
// if (next != processed_tables_.end()) {
// return;
// }
// table_info_stack_.push({*result, std::make_shared<table>(info.name(), build_alias('t', ++table_index))});
// next = processed_tables_.insert({info.name(), table_info_stack_.top().table}).first;
// typename ContainerType::value_type::value_type obj;
// access::process(*this , obj);
// table_info_stack_.pop();
//
// if (!info.has_primary_key()) {
// throw query_builder_exception{query_build_error::MissingPrimaryKey};
// }
//
// append_join(
// column{table_info_stack_.top().table.get(), table_info_stack_.top().info.get().primary_key_attribute()->name()},
// column{next->second.get(), join_column}
// );
template<class CollectionType>
void on_has_many(const char * /*id*/, CollectionType &, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
}
template<class ContainerType>