has one progress

This commit is contained in:
2026-05-15 15:22:59 +02:00
parent 22f6f71412
commit 57703dfb67
44 changed files with 288 additions and 121 deletions
@@ -63,15 +63,9 @@ public:
void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr);
template<class Pointer>
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
on_foreign_key(x, attr);
}
template<class Pointer>
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
on_foreign_key(x, attr);
}
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr);
template<class PointerType>
void on_has_one(const char * /*id*/, object::object_ptr<PointerType> &x, const char * /*join_column*/, const utils::foreign_attributes &attr);
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);
template<class CollectionType>
@@ -103,23 +97,6 @@ private:
return resolver.discover(obj);
}
template<class Pointer>
void on_foreign_key(Pointer &x, const utils::foreign_attributes &attr) {
const auto resolver = resolver_->object_resolver<typename Pointer::value_type>();
if (attr.fetch() == utils::fetch_type::Lazy) {
typename Pointer::value_type obj;
auto pk = id_reader_.read(obj, column_index_++);
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, pk));
} else {
auto obj = std::make_shared<typename Pointer::value_type>();
const auto ti = std::type_index(typeid(*x));
type_stack_.push(ti);
access::process(*this, *obj);
type_stack_.pop();
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, obj));
}
}
protected:
size_t column_index_ = 0;
std::vector<object::attribute> prototype_;
@@ -134,6 +111,38 @@ protected:
std::unordered_set<object::collection_composite_key, object::collection_composite_key_hash> initialized_collections_;
};
template <class Pointer>
void query_result_impl::on_belongs_to(const char*, Pointer& x, const utils::foreign_attributes& attr) {
const auto resolver = resolver_->object_resolver<typename Pointer::value_type>();
if (attr.fetch() == utils::fetch_type::Lazy) {
typename Pointer::value_type obj;
auto pk = id_reader_.read(obj, column_index_++);
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, pk));
} else {
auto obj = std::make_shared<typename Pointer::value_type>();
const auto ti = std::type_index(typeid(*x));
type_stack_.push(ti);
access::process(*this, *obj);
type_stack_.pop();
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, obj));
}
}
template <class PointerType>
void query_result_impl::on_has_one(const char*, object::object_ptr<PointerType>& x, const char *join_column, const utils::foreign_attributes& attr) {
const auto resolver = resolver_->collection_resolver<PointerType>(result_type_, join_column);
if (attr.fetch() == utils::fetch_type::Lazy) {
x = object::object_ptr<PointerType>(std::make_shared<object::object_proxy<PointerType>>(resolver, id_reader_.read(x, column_index_++)));
} else {
auto obj = std::make_shared<PointerType>();
const auto ti = std::type_index(typeid(*x));
type_stack_.push(ti);
access::process(*this, *obj);
type_stack_.pop();
x = object::object_ptr<PointerType>(std::make_shared<object::object_proxy<PointerType>>(resolver, obj));
}
}
template <class CollectionType>
void query_result_impl::on_has_many(const char *, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> *) {
using value_type = typename CollectionType::value_type::value_type;