object changes
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
#include <algorithm>
|
||||
|
||||
namespace matador::object {
|
||||
object_generator::object_generator( const repository& repo, std::unique_ptr<object>&& object )
|
||||
object_generator::object_generator(repository& repo, const std::shared_ptr<object>& object)
|
||||
: repo_(repo)
|
||||
, object_(std::move(object)) {}
|
||||
, object_(object) {}
|
||||
|
||||
void object_generator::on_revision(const char* id, uint64_t& rev) {
|
||||
on_attribute(id, rev);
|
||||
@@ -19,28 +19,24 @@ void object_generator::create_pk_constraint(const std::string& name) const {
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(object_->attributes_)) {
|
||||
pk_constraint.attr_ = &*pk_attr;
|
||||
}
|
||||
pk_constraint.owner_ = object_.get();
|
||||
pk_constraint.owner_ = object_;
|
||||
object_->constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
void object_generator::create_fk_constraint(const std::type_index& ti, const std::string& name) const {
|
||||
const auto result = repo_.basic_info(ti);
|
||||
if (!result) {
|
||||
repo_.provide_object_in_advance(ti, std::make_shared<object>(""));
|
||||
repo_.has_object_for_type(ti);
|
||||
repo_.object_for_type(ti);
|
||||
repo_.remove_object_for_type(ti);
|
||||
return;
|
||||
}
|
||||
const auto *pk_attribute = result->get().primary_key_attribute();
|
||||
const auto obj = fk_object(ti);
|
||||
const auto *pk_attribute = obj->primary_key_attribute();
|
||||
class constraint pk_constraint("FK_" + object_->name() + "_" + name);
|
||||
pk_constraint.options_ |= utils::constraints::ForeignKey;
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(object_->attributes_)) {
|
||||
pk_constraint.attr_ = &*pk_attr;
|
||||
}
|
||||
pk_constraint.owner_ = object_.get();
|
||||
pk_constraint.ref_column_name_ = pk_attribute->name();
|
||||
pk_constraint.ref_table_name_ = pk_attribute->owner() ? pk_attribute->owner()->name() : "";
|
||||
pk_constraint.owner_ = object_;
|
||||
pk_constraint.reference_ = obj;
|
||||
if (pk_attribute) {
|
||||
pk_constraint.ref_column_name_ = pk_attribute->name();
|
||||
pk_constraint.ref_table_name_ = pk_attribute->owner() ? pk_attribute->owner()->name() : "";
|
||||
}
|
||||
object_->constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
@@ -50,7 +46,7 @@ void object_generator::create_unique_constraint(const std::string& name) const {
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(object_->attributes_)) {
|
||||
pk_constraint.attr_ = &*pk_attr;
|
||||
}
|
||||
pk_constraint.owner_ = object_.get();
|
||||
pk_constraint.owner_ = object_;
|
||||
}
|
||||
|
||||
std::list<attribute>::iterator object_generator::find_attribute_by_name(const std::string& name) const {
|
||||
@@ -63,4 +59,13 @@ void object_generator::prepare_primary_key(attribute& ref, utils::identifier &&p
|
||||
object_->pk_attribute_ = &ref;
|
||||
object_->pk_identifier_ = std::move(pk);
|
||||
}
|
||||
|
||||
std::shared_ptr<class object> object_generator::fk_object(const std::type_index& ti) const {
|
||||
const auto result = repo_.basic_info(ti);
|
||||
if (result) {
|
||||
return result->get().object();
|
||||
}
|
||||
|
||||
return repo_.provide_object_in_advance(ti, std::make_shared<object>(""));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user