diff --git a/include/matador/object/relation_completer.hpp b/include/matador/object/relation_completer.hpp index 04c71f8..5a2377a 100644 --- a/include/matador/object/relation_completer.hpp +++ b/include/matador/object/relation_completer.hpp @@ -155,18 +155,6 @@ private: join_columns_collector join_columns_collector_{}; }; -inline void dump(std::ostream &os, const std::shared_ptr &node) { - os << "node [" << node->name() << "] (" /*<< node->type_index().name()*/ << ")\n"; - for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) { - os << " " << node->name() << "::" << it->second->field_name() << " (" << it->second->type_name() << ")"; - if (it->second->foreign_endpoint()) { - os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n"; - } else { - os << " -> " << it->second->node().type_index().name() << "\n"; - } - } - -} template template void relation_completer::on_has_many(const char *id, CollectionType &, @@ -199,7 +187,6 @@ void relation_completer::on_has_many(const char *id, CollectionType &, nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint); } else { // A relation table is necessary - // } else if (const auto endpoint = nodes_.top()->info().find_relation_endpoint(typeid(relation_value_type)); endpoint == nodes_.top()->info().endpoint_end()) { // 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 @@ -221,77 +208,7 @@ void relation_completer::on_has_many(const char *id, CollectionType &, const auto foreign_value_endpoint = std::make_shared(join_column, relation_type::BELONGS_TO, foreign_node); result.value()->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint); - - // dump( std::cout, nodes_.top() ); - // dump( std::cout, result.value() ); - // if (const auto detach_result = schema_.detach_node(foreign_node); !detach_result) { - // // Todo: throw internal error - // return; - // } } - // } else { - // if (const auto rit = foreign_node->info_->find_relation_endpoint(nodes_.top()->type_index()); - // rit != foreign_node->info().endpoint_end()) { - // if (rit->second->is_belongs_to()) { - // rit->second->node_ = foreign_node; - // const auto localEndpoint = std::make_shared(id, relation_type::HAS_MANY, nodes_.top()); - // nodes_.top()->info_->register_relation_endpoint(nodes_.top()->type_index(), localEndpoint); - // link_relation_endpoints(localEndpoint, rit->second); - // } else { - // // Todo: throw internal error relation node has invalid type - // } - // } else { - // // Todo: throw internal error couldn't find relation node - // } - // } - - // auto local_it = nodes_.top()->info().find_relation_endpoint(typeid(value_type)); - // if (local_it == nodes_.top()->info().endpoint_end()) { - // const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, result.value()); - // local_it = nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint); - // } - // auto foreign_it = result.value()->info().find_relation_endpoint(typeid(value_type)); - // if (foreign_it == result.value()->info().endpoint_end()) { - // const auto foreign_endpoint = std::make_shared(join_column, relation_type::BELONGS_TO, nodes_.top()); - // foreign_it = result.value()->info_->register_relation_endpoint(typeid(Type), foreign_endpoint); - // } - // link_relation_endpoints(local_it->second, foreign_it->second); - - /* - if (const auto endpoint = nodes_.top()->info().find_relation_endpoint(typeid(relation_value_type)); endpoint == nodes_.top()->info().endpoint_end()) { - // Endpoint was not found - log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column); - result = schema_node::make_relation_node( - schema_.schema(), id, [join_column] { - return std::make_unique("id", join_column); - }); - if (!result) { - // Todo: throw internal error - return; - } - const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, nodes_.top()); - const auto foreign_endpoint = std::make_shared(join_column, relation_type::BELONGS_TO, result.value()); - nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint); - foreign_endpoint->node_->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint); - link_relation_endpoints(local_endpoint, foreign_endpoint); - } else { - const auto &foreign_node = result.value(); - if (const auto rit = foreign_node->info_->find_relation_endpoint(nodes_.top()->type_index()); - rit != foreign_node->info().endpoint_end()) { - if (rit->second->is_belongs_to()) { - rit->second->node_ = foreign_node; - const auto localEndpoint = std::make_shared(id, relation_type::HAS_MANY, nodes_.top()); - nodes_.top()->info_->register_relation_endpoint(nodes_.top()->type_index(), localEndpoint); - link_relation_endpoints(localEndpoint, rit->second); - } else { - // Todo: throw internal error relation node has invalid type - } - } else { - // Todo: throw internal error couldn't find relation node - } - - } - */ } template @@ -310,10 +227,9 @@ void relation_completer::on_has_many(const char *id, CollectionType &, con if (!result) { // Todo: throw internal exception + return; } - // const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, nodes_.top()); - // const auto foreign_endpoint = std::make_shared(join_column, relation_type::BELONGS_TO, result.value()); const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, result.value()); const auto foreign_endpoint = std::make_shared(join_column, relation_type::BELONGS_TO, nodes_.top());