removed redundant code in relation completer
This commit is contained in:
@@ -385,42 +385,15 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
|
||||
template<typename Type>
|
||||
template<class CollectionType>
|
||||
void relation_completer<Type>::on_has_many_to_many(const char *id,
|
||||
CollectionType &/*collection*/,
|
||||
const utils::foreign_attributes &/*attr*/) {
|
||||
auto result = schema_.find_node(id);
|
||||
if (!result) {
|
||||
const auto join_columns = join_columns_collector_.collect<typename CollectionType::value_type::value_type>();
|
||||
using relation_value_type = many_to_many_relation<typename CollectionType::value_type::value_type, Type>;
|
||||
auto creator = [&join_columns] {
|
||||
return std::make_unique<relation_value_type>(join_columns.inverse_join_column, join_columns.join_column);
|
||||
};
|
||||
|
||||
auto node = schema_node::make_relation_node<relation_value_type>(schema_, id, std::move(creator));
|
||||
|
||||
auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
|
||||
auto join_endpoint = std::make_shared<relation_endpoint>(join_columns.join_column, relation_type::BELONGS_TO, node);
|
||||
auto inverse_join_endpoint = std::make_shared<relation_endpoint>(join_columns.inverse_join_column,
|
||||
relation_type::BELONGS_TO, node);
|
||||
node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint);
|
||||
node->info_->register_relation_endpoint(node_->type_index(), inverse_join_endpoint);
|
||||
link_relation_endpoints(local_endpoint, inverse_join_endpoint);
|
||||
node->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), join_endpoint);
|
||||
result = schema_.attach_node(node, "");
|
||||
if (!result) {
|
||||
// Todo: throw internal error
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
const auto &foreign_node = result.value();
|
||||
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
|
||||
node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint);
|
||||
const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index());
|
||||
if (it == foreign_node->info().endpoint_end()) {
|
||||
// Todo: Throw internal error
|
||||
return;
|
||||
}
|
||||
link_relation_endpoints(local_endpoint, it->second);
|
||||
}
|
||||
CollectionType &collection,
|
||||
const utils::foreign_attributes &attr) {
|
||||
const auto join_columns = join_columns_collector_.collect<typename CollectionType::value_type::value_type>();
|
||||
on_has_many_to_many(
|
||||
id,
|
||||
collection,
|
||||
join_columns.inverse_join_column.c_str(),
|
||||
join_columns.join_column.c_str(),
|
||||
attr);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
||||
Reference in New Issue
Block a user