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> {
|
template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
|
||||||
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
|
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 LdapUserDirectory;
|
||||||
|
|
||||||
struct LdapGroupSchemaSettings : core::Model {
|
struct LdapGroupSchemaSettings : core::Model {
|
||||||
std::string group_object_filter;
|
std::string group_object_filter{};
|
||||||
std::string user_member_attribute;
|
std::string user_member_attribute{};
|
||||||
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory;
|
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory{};
|
||||||
|
|
||||||
template<typename Operator>
|
template<typename Operator>
|
||||||
void process( Operator& op ) {
|
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, "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, "group_schema_settings", group_schema_settings, matador::utils::CascadeAllFetchLazy );
|
||||||
field::belongs_to( op, "import_settings", import_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_users", users, "users_id", matador::utils::CascadeAllFetchEager );
|
||||||
field::has_many( op, "ldap_groups", groups, "groups_id", matador::utils::CascadeAllFetchLazy );
|
field::has_many( op, "ldap_groups", groups, "groups_id", matador::utils::CascadeAllFetchEager );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ namespace work::models::admin {
|
||||||
struct LdapUserDirectory;
|
struct LdapUserDirectory;
|
||||||
|
|
||||||
struct LdapUserSchemaSettings : core::Model {
|
struct LdapUserSchemaSettings : core::Model {
|
||||||
std::string user_object_filter;
|
std::string user_object_filter{};
|
||||||
std::string user_unique_id_attribute;
|
std::string user_unique_id_attribute{};
|
||||||
std::string user_member_of_attribute;
|
std::string user_member_of_attribute{};
|
||||||
std::string user_name_attribute;
|
std::string user_name_attribute{};
|
||||||
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory;
|
matador::object::object_ptr<LdapUserDirectory> ldap_user_directory{};
|
||||||
|
|
||||||
template<typename Operator>
|
template<typename Operator>
|
||||||
void process( Operator& op ) {
|
void process( Operator& op ) {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
namespace work::core {
|
namespace work::core {
|
||||||
struct Model {
|
struct Model {
|
||||||
uint64_t id;
|
uint64_t id{};
|
||||||
uint64_t version;
|
uint64_t version{};
|
||||||
|
|
||||||
template<typename Operator>
|
template<typename Operator>
|
||||||
void process( Operator& op ) {
|
void process( Operator& op ) {
|
||||||
|
|
|
||||||
|
|
@ -83,12 +83,12 @@ public:
|
||||||
on_foreign_key(id, x, attr);
|
on_foreign_key(id, x, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class CollectionType>
|
||||||
void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &attr) {
|
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)) {
|
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
|
||||||
return;
|
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()) {
|
if (it == repo_.end()) {
|
||||||
// Todo: throw exception
|
// Todo: throw exception
|
||||||
return;
|
return;
|
||||||
|
|
@ -97,13 +97,17 @@ public:
|
||||||
if (seen_tables.count(it->second.name()) == 0) {
|
if (seen_tables.count(it->second.name()) == 0) {
|
||||||
const auto itt = seen_tables.insert(it->second.name()).first;
|
const auto itt = seen_tables.insert(it->second.name()).first;
|
||||||
table_stack_.push(&it->second.table());
|
table_stack_.push(&it->second.table());
|
||||||
typename ContainerType::value_type::value_type obj;
|
typename CollectionType::value_type::value_type obj;
|
||||||
access::process(*this, obj);
|
access::process(*this, obj);
|
||||||
table_stack_.pop();
|
table_stack_.pop();
|
||||||
seen_tables.erase(itt);
|
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>
|
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) {
|
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)) {
|
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 {}
|
void operator()(const T*) const {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class CollectionType>
|
||||||
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
|
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) {
|
if (attr.fetch() != utils::fetch_type::Eager) {
|
||||||
return;
|
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()) {
|
if (it == schema_.end()) {
|
||||||
throw query_builder_exception{query_build_error::UnknownType};
|
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))});
|
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;
|
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);
|
access::process(*this , obj);
|
||||||
table_info_stack_.pop();
|
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{&table_info_stack_.top().table, table_info_stack_.top().info.primary_key_attribute()->name()},
|
||||||
table_column{&next->second, join_column}
|
table_column{&next->second, join_column}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CollectionType>
|
||||||
// const auto result = schema_.repo().basic_info(typeid(typename ContainerType::value_type::value_type));
|
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 (!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 ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "matador/object/attribute.hpp"
|
#include "matador/object/attribute.hpp"
|
||||||
#include "matador/object/object_proxy.hpp"
|
#include "matador/object/object_proxy.hpp"
|
||||||
|
#include "matador/object/object_ptr.hpp"
|
||||||
#include "matador/object/object_resolver_factory.hpp"
|
#include "matador/object/object_resolver_factory.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -122,20 +123,20 @@ public:
|
||||||
} else {}
|
} else {}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class CollectionType>
|
||||||
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
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 ContainerType::value_type::value_type;
|
using value_type = typename CollectionType::value_type::value_type;
|
||||||
auto resolver = resolver_factory_->resolver<value_type>();
|
auto resolver = resolver_factory_->resolver<value_type>();
|
||||||
|
|
||||||
if (attr.fetch() == utils::fetch_type::Lazy) {
|
if (attr.fetch() == utils::fetch_type::Lazy) {
|
||||||
// pk_reader_.read(*id, column_index_++);
|
// pk_reader_.read(*id, column_index_++);
|
||||||
} else {
|
} else {
|
||||||
const auto ti = std::type_index(typeid(value_type));
|
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);
|
type_stack_.push(ti);
|
||||||
access::process(*this, *obj);
|
access::process(*this, *obj);
|
||||||
type_stack_.pop();
|
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();
|
const auto pk = ptr.primary_key();
|
||||||
if (ptr.primary_key().is_valid()) {
|
if (ptr.primary_key().is_valid()) {
|
||||||
cont.push_back(ptr);
|
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>
|
template<class Type>
|
||||||
void bind(const Type &obj) {
|
void bind(const Type &obj) {
|
||||||
reader_->bind(obj);
|
reader_->bind(obj);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue