added has_many for non object_ptr types
This commit is contained in:
parent
5dae396842
commit
4c899ae2f2
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
|
||||
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
|
||||
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
||||
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, work::core::UserInfo &/*value*/) {
|
||||
|
||||
}
|
||||
static void bind_value(attribute_writer &/*binder*/, size_t /*index*/, nullptr_t &/*value*/) {
|
||||
static void bind_value(attribute_writer &/*binder*/, size_t /*index*/, work::core::UserInfo &/*value*/) {
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ namespace work::models::admin {
|
|||
struct LdapUserDirectory;
|
||||
|
||||
struct LdapGroupSchemaSettings : core::Model {
|
||||
std::string group_object_filter;
|
||||
std::string user_member_attribute;
|
||||
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory;
|
||||
std::string group_object_filter{};
|
||||
std::string user_member_attribute{};
|
||||
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory{};
|
||||
|
||||
template<typename Operator>
|
||||
void process( Operator& op ) {
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ struct LdapUserDirectory : UserDirectory {
|
|||
field::belongs_to( op, "user_schema_settings", user_schema_settings, matador::utils::CascadeAllFetchLazy );
|
||||
field::belongs_to( op, "group_schema_settings", group_schema_settings, matador::utils::CascadeAllFetchLazy );
|
||||
field::belongs_to( op, "import_settings", import_settings, matador::utils::CascadeAllFetchLazy );
|
||||
field::has_many( op, "ldap_users", users, "users_id", matador::utils::CascadeAllFetchLazy );
|
||||
field::has_many( op, "ldap_groups", groups, "groups_id", matador::utils::CascadeAllFetchLazy );
|
||||
field::has_many( op, "ldap_users", users, "users_id", matador::utils::CascadeAllFetchEager );
|
||||
field::has_many( op, "ldap_groups", groups, "groups_id", matador::utils::CascadeAllFetchEager );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ namespace work::models::admin {
|
|||
struct LdapUserDirectory;
|
||||
|
||||
struct LdapUserSchemaSettings : core::Model {
|
||||
std::string user_object_filter;
|
||||
std::string user_unique_id_attribute;
|
||||
std::string user_member_of_attribute;
|
||||
std::string user_name_attribute;
|
||||
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory;
|
||||
std::string user_object_filter{};
|
||||
std::string user_unique_id_attribute{};
|
||||
std::string user_member_of_attribute{};
|
||||
std::string user_name_attribute{};
|
||||
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory{};
|
||||
|
||||
template<typename Operator>
|
||||
void process( Operator& op ) {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
namespace work::core {
|
||||
struct Model {
|
||||
uint64_t id;
|
||||
uint64_t version;
|
||||
uint64_t id{};
|
||||
uint64_t version{};
|
||||
|
||||
template<typename Operator>
|
||||
void process( Operator& op ) {
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue