object generation
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "matador/object/object.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace matador::object {
|
||||
constraints_generator::constraints_generator(std::vector<class constraint> &constraints, const repository& repo, object &obj)
|
||||
: constraints_(constraints)
|
||||
@@ -18,8 +20,12 @@ void constraints_generator::create_pk_constraint(const std::string& name) const
|
||||
constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
void constraints_generator::create_fk_constraint(const std::string& name, const basic_object_info& info) const {
|
||||
const auto *pk_attribute = info.primary_key_attribute();
|
||||
void constraints_generator::create_fk_constraint(const std::type_index& ti, const std::string& name) const {
|
||||
const auto result = repo_.basic_info(ti);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
const auto *pk_attribute = result.value().get().primary_key_attribute();
|
||||
class constraint pk_constraint("FK_" + obj_.name() + "_" + name);
|
||||
pk_constraint.options_ |= utils::constraints::ForeignKey;
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(obj_.attributes_)) {
|
||||
|
||||
@@ -53,6 +53,15 @@ bool repository::contains( const std::type_index& index ) const {
|
||||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
utils::result<basic_object_info_ref, utils::error> repository::basic_info(const std::type_index &ti) const {
|
||||
auto result = find_node(ti);
|
||||
if (!result) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
return utils::ok(basic_object_info_ref{result.value()->info()});
|
||||
}
|
||||
|
||||
utils::result<basic_object_info_ref, utils::error> repository::basic_info( const std::string& name ) const {
|
||||
auto result = find_node(name);
|
||||
if (!result) {
|
||||
|
||||
Reference in New Issue
Block a user