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
@@ -15,6 +15,7 @@
#include "matador/object/attribute.hpp"
#include "matador/object/object_proxy.hpp"
#include "matador/object/object_ptr.hpp"
#include "matador/object/object_resolver_factory.hpp"
#include <memory>
@@ -122,20 +123,20 @@ public:
} else {}
}
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr) {
using value_type = typename ContainerType::value_type::value_type;
template<class CollectionType>
void on_has_many(const char * /*id*/, CollectionType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
using value_type = typename CollectionType::value_type::value_type;
auto resolver = resolver_factory_->resolver<value_type>();
if (attr.fetch() == utils::fetch_type::Lazy) {
// pk_reader_.read(*id, column_index_++);
} else {
const auto ti = std::type_index(typeid(value_type));
auto obj = std::make_shared<typename ContainerType::value_type::value_type>();
auto obj = std::make_shared<typename CollectionType::value_type::value_type>();
type_stack_.push(ti);
access::process(*this, *obj);
type_stack_.pop();
auto ptr = typename ContainerType::value_type(std::make_shared<object::object_proxy<value_type>>(resolver, obj));
auto ptr = typename CollectionType::value_type(std::make_shared<object::object_proxy<value_type>>(resolver, obj));
const auto pk = ptr.primary_key();
if (ptr.primary_key().is_valid()) {
cont.push_back(ptr);
@@ -143,6 +144,10 @@ public:
}
}
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 Type>
void bind(const Type &obj) {
reader_->bind(obj);