relation_completer progress
This commit is contained in:
parent
38cbffc18b
commit
c4a00f19fd
|
|
@ -33,11 +33,14 @@ public:
|
|||
[[nodiscard]] bool is_has_many() const;
|
||||
[[nodiscard]] bool is_belongs_to() const;
|
||||
|
||||
[[nodiscard]] std::shared_ptr<relation_endpoint> foreign_endpoint() const;
|
||||
void link_foreign_endpoint(const std::shared_ptr<relation_endpoint>& endpoint);
|
||||
|
||||
private:
|
||||
std::string field_name_;
|
||||
relation_type type_;
|
||||
std::shared_ptr<schema_node> node_;
|
||||
std::weak_ptr<relation_endpoint> foreign_endpoint;
|
||||
std::shared_ptr<relation_endpoint> foreign_endpoint_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,9 +81,7 @@ public:
|
|||
on_foreign_key<ForeignPointerType>();
|
||||
}
|
||||
template<class ForeignPointerType>
|
||||
void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/) {
|
||||
on_foreign_key<ForeignPointerType>();
|
||||
}
|
||||
void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/);
|
||||
|
||||
template<class CollectionType>
|
||||
void on_has_many(const char *id, CollectionType &, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<is_object_ptr<typename CollectionType::value_type>::value>* = nullptr );
|
||||
|
|
@ -248,18 +246,11 @@ template<class CollectionType>
|
|||
void relation_completer<Type>::on_has_many( const char *id, CollectionType&, const char *join_column, const utils::foreign_attributes&, std::enable_if_t<is_object_ptr<typename CollectionType::value_type>::value>* /*unused*/ ) {
|
||||
using value_type = typename CollectionType::value_type;
|
||||
|
||||
// Process foreign key has many relation
|
||||
// Check if foreign key type was already registered
|
||||
auto result = schema_.find_node(typeid(value_type));
|
||||
if (result) {
|
||||
} else {
|
||||
//
|
||||
using relation_type = many_to_many_relation<value_type, Type>;
|
||||
auto creator = [] {
|
||||
return new many_to_many_relation<value_type, Type>();
|
||||
};
|
||||
}
|
||||
const auto node = schema_node::make_relation_node<many_to_many_relation<value_type, Type>>(schema_, id, [join_column] {
|
||||
return new many_to_many_relation<value_type, Type>(join_column, "id");
|
||||
});
|
||||
|
||||
schema_.attach_node(node, typeid(many_to_many_relation<value_type, Type>));
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
|
@ -267,20 +258,14 @@ template<class CollectionType>
|
|||
void relation_completer<Type>::on_has_many( const char *id, CollectionType&, const char *join_column, const utils::foreign_attributes&, std::enable_if_t<!is_object_ptr<typename CollectionType::value_type>::value>* /*unused*/ ) {
|
||||
using value_type = typename CollectionType::value_type;
|
||||
|
||||
// Process values has many relation
|
||||
// Register relation table
|
||||
const auto node = schema_node::make_relation_node<many_to_many_relation<value_type, Type>>(schema_, id, [join_column] {
|
||||
return new many_to_many_relation<value_type, Type>(join_column, "value");
|
||||
});
|
||||
|
||||
// many_to_relation<Type, value_type> *relation = new many_to_relation<Type, value_type>(join_column, "value");
|
||||
auto result = schema_.find_node(typeid(value_type));
|
||||
if (result) {
|
||||
} else {
|
||||
//
|
||||
using relation_type = many_to_many_relation<value_type, Type>;
|
||||
auto creator = [] {
|
||||
return new many_to_many_relation<value_type, Type>();
|
||||
};
|
||||
const auto result = schema_.attach<many_to_many_relation<value_type, Type>>(id);
|
||||
if (!result) {
|
||||
// Todo: throw internal exception
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
|
@ -308,7 +293,8 @@ void relation_completer<Type>::on_has_many_to_many( const char *id, ContainerTyp
|
|||
|
||||
template<typename Type>
|
||||
template<class ForeignPointerType>
|
||||
void relation_completer<Type>::on_foreign_key() {
|
||||
void relation_completer<Type>::on_has_one(const char * id, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/) {
|
||||
auto endpoint = std::make_shared<relation_endpoint>(std::string(id), relation_type::HAS_ONE, std::shared_ptr<schema_node>());
|
||||
auto ti = std::type_index(typeid(typename ForeignPointerType::value_type));
|
||||
if (const auto result = schema_.find_node(ti); !result.is_ok() && schema_.expected_node_map_.count(ti) == 0) {
|
||||
schema_.expected_node_map_.insert({ti, schema_node::make_node<typename ForeignPointerType::value_type>(schema_, ti.name())});
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ public:
|
|||
return node;
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
static std::shared_ptr<schema_node> make_relation_node(object::schema& tree, const std::string& name) {
|
||||
template < typename Type, typename CreatorFunc >
|
||||
static std::shared_ptr<schema_node> make_relation_node(object::schema& tree, const std::string& name, CreatorFunc &&creator) {
|
||||
auto node = std::shared_ptr<schema_node>(new schema_node(tree, name));
|
||||
|
||||
auto info = std::make_unique<object_info<Type>>(
|
||||
|
|
@ -69,7 +69,7 @@ public:
|
|||
return std::ref(static_cast<const object_info<Type>&>(*info_));
|
||||
}
|
||||
|
||||
const object::schema& schema() const;
|
||||
[[nodiscard]] const object::schema& schema() const;
|
||||
|
||||
private:
|
||||
explicit schema_node(object::schema& tree);
|
||||
|
|
|
|||
|
|
@ -32,4 +32,12 @@ bool relation_endpoint::is_has_many() const {
|
|||
bool relation_endpoint::is_belongs_to() const {
|
||||
return type_ == relation_type::BELONGS_TO;
|
||||
}
|
||||
|
||||
std::shared_ptr<relation_endpoint> relation_endpoint::foreign_endpoint() const {
|
||||
return foreign_endpoint_;
|
||||
}
|
||||
|
||||
void relation_endpoint::link_foreign_endpoint( const std::shared_ptr<relation_endpoint>& endpoint ) {
|
||||
foreign_endpoint_ = endpoint;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue