46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#ifndef MATADOR_RELATION_ENDPOINT_HPP
|
|
#define MATADOR_RELATION_ENDPOINT_HPP
|
|
|
|
#include "matador/utils/enum_mapper.hpp"
|
|
|
|
#include <memory>
|
|
|
|
namespace matador::object {
|
|
|
|
class schema_node;
|
|
|
|
enum class relation_type : uint8_t {
|
|
BELONGS_TO,
|
|
HAS_ONE,
|
|
HAS_MANY
|
|
};
|
|
|
|
static const utils::enum_mapper<relation_type> relation_type_enum({
|
|
{ relation_type::BELONGS_TO, "belongs_to" },
|
|
{ relation_type::HAS_ONE, "has_one" },
|
|
{ relation_type::HAS_MANY, "has_many" },
|
|
});
|
|
|
|
class relation_endpoint {
|
|
public:
|
|
relation_endpoint(std::string field_name, relation_type type, const std::shared_ptr<schema_node>& node);
|
|
|
|
[[nodiscard]] std::string field_name() const;
|
|
[[nodiscard]] relation_type type() const;
|
|
[[nodiscard]] const schema_node& node() const;
|
|
|
|
[[nodiscard]] bool is_has_one() const;
|
|
[[nodiscard]] bool is_has_many() const;
|
|
[[nodiscard]] bool is_belongs_to() const;
|
|
|
|
private:
|
|
std::string field_name_;
|
|
relation_type type_;
|
|
std::shared_ptr<schema_node> node_;
|
|
std::weak_ptr<relation_endpoint> foreign_endpoint;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //MATADOR_RELATION_ENDPOINT_HPP
|