has many primitive relation progress

This commit is contained in:
2026-05-08 15:53:52 +02:00
parent 1e08996087
commit a714cd2a53
6 changed files with 89 additions and 6 deletions
@@ -46,6 +46,11 @@ public:
many_to_relation(std::string local_name, std::string remote_name)
: local_name_(std::move(local_name))
, type_name_(std::move(remote_name)) {}
many_to_relation(std::string local_name, std::string remote_name, const object_ptr<LocalType>& local, const Type& value)
: local_name_(std::move(local_name))
, type_name_(std::move(remote_name))
, local_(local)
, value_(value){}
template<class Operator>
void process(Operator &op) {
@@ -227,9 +227,11 @@ void relation_completer<Type, Observers...>::on_has_many(const char *id, Collect
using value_type = typename CollectionType::value_type;
using relation_value_type = many_to_relation<Type, value_type>;
auto observers = internal::observer_list_copy_creator<Type, relation_value_type, Observers...>::copy_create(observers_);
auto node = repository_node::make_node<relation_value_type>(repo_, id, [join_column] {
return std::make_unique<relation_value_type>(join_column, "value");
}, {});
}, std::move(observers));
const auto result = repo_.attach_node(node.release(), "");
if (!result) {
// Todo: throw internal exception
+33 -2
View File
@@ -104,7 +104,10 @@ public:
on_foreign_object(obj, attr);
}
template<class CollectionType>
void on_has_many(const char * /*id*/, object::collection<object::object_ptr<CollectionType>> &objects, const char *join_column, const utils::foreign_attributes &attr) {
void on_has_many(const char * /*id*/,
object::collection<object::object_ptr<CollectionType>> &objects,
const char *join_column,
const utils::foreign_attributes &attr) {
if (!utils::is_cascade_type_set(attr.cascade(), utils::cascade_type::Insert)) {
return;
}
@@ -120,7 +123,35 @@ public:
}
template<class CollectionType>
static void on_has_many(const char * /*id*/, object::collection<CollectionType> &/*con*/, const char *, const utils::foreign_attributes &/*attr*/) {}
void on_has_many(const char *id,
object::collection<CollectionType> &objects,
const char *join_column,
const utils::foreign_attributes &attr) {
if (!utils::is_cascade_type_set(attr.cascade(), utils::cascade_type::Insert)) {
return;
}
const auto it = schema_.find(std::string{id});
if (it == schema_.end()) {
throw query_builder_exception(error_code::UnknownType, "Unknown type " + std::string{id});
}
using relation_value_type = object::many_to_relation<ObjectType, CollectionType>;
if (std::type_index(typeid(relation_value_type)) != it->second.node().info().type_index()) {
throw query_builder_exception(error_code::InvalidRelationType, "Invalid relation type");
}
const auto cit = contexts_by_type_.find(it->second.node().info().type_index());
if (cit == contexts_by_type_.end()) {
throw query_builder_exception(error_code::UnknownType, "Unknown type" + std::string{id});
}
for (auto &obj : objects) {
auto rel = object::make_object<relation_value_type>(join_column, "value", ptr_, obj);
relation_steps_.push_back(std::make_unique<insert_step_relation<relation_value_type>>(cit->second.insert, rel));
}
}
template<class ForeignType>
void on_has_many_to_many(const char *id, object::collection<object::object_ptr<ForeignType>> &objects, const char *join_column, const char *inverse_join_column, const utils::foreign_attributes &attr) {
+1 -3
View File
@@ -94,9 +94,7 @@ public:
}
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) {
}
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>
void on_has_many_to_many(const char *id, CollectionType &, const char *join_column, const char *inverse_join_column, const utils::foreign_attributes &/*attr*/) {