removed make_relation_node method from repository_node

This commit is contained in:
2025-12-08 19:45:35 +01:00
parent 263c202c69
commit d4ef97ef5a
15 changed files with 90 additions and 133 deletions
+29 -30
View File
@@ -186,28 +186,28 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &,
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, foreign_node);
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
} else {
// A relation table is necessary
// Endpoint was not found.
// Always attach a many-to-many relation type. If later a
// belongs-to relation handles this relation, the many-to-many
// relation is maybe detached.
log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column);
result = repository_node::make_relation_node<relation_value_type>(
schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>("id", join_column);
});
if (!result) {
// Todo: throw internal error
return;
}
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, result.value());
const auto foreign_endpoint = std::make_shared<relation_endpoint>("id", relation_type::BelongsTo, nodes_.top());
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
result.value()->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
link_relation_endpoints(local_endpoint, foreign_endpoint);
// A relation table is necessary
// Endpoint was not found.
// Always attach a many-to-many relation type. If later a
// belongs-to relation handles this relation, the many-to-many
// relation is maybe detached.
log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column);
auto node = repository_node::make_node<relation_value_type>(schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>("id", join_column);
});
result = schema_.attach_node(node);
if (!result) {
// Todo: throw internal error
return;
}
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
const auto foreign_endpoint = std::make_shared<relation_endpoint>("id", relation_type::BelongsTo, nodes_.top());
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
node->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
link_relation_endpoints(local_endpoint, foreign_endpoint);
const auto foreign_value_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, foreign_node);
result.value()->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint);
const auto foreign_value_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, foreign_node);
node->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint);
}
}
@@ -220,21 +220,20 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &, con
using value_type = typename CollectionType::value_type;
using relation_value_type = many_to_relation<Type, value_type>;
const auto result = repository_node::make_relation_node<relation_value_type>(
schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>(join_column, "value");
});
auto node = repository_node::make_node<relation_value_type>(schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>(join_column, "value");
});
const auto result = schema_.attach_node(node);
if (!result) {
// Todo: throw internal exception
return;
}
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, result.value());
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
const auto foreign_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, nodes_.top());
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
result.value()->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
node->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
link_relation_endpoints(local_endpoint, foreign_endpoint);
}
@@ -265,13 +264,13 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
return std::make_unique<relation_value_type>(join_column, inverse_join_column);
};
result = repository_node::make_relation_node<relation_value_type>(schema_.repo(), id, std::move(creator));
auto node = repository_node::make_node<relation_value_type>(schema_.repo(), id, std::move(creator));
result = schema_.attach_node(node);
if (!result) {
// Todo: throw internal error
return;
}
auto& node = result.value();
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
const auto join_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, nodes_.top());
const auto inverse_join_endpoint = std::make_shared<relation_endpoint>(inverse_join_column, relation_type::BelongsTo, foreign_node);