added join_column_index and inverse_join_column_index to object and table classes
This commit is contained in:
@@ -58,7 +58,11 @@ public:
|
||||
}
|
||||
|
||||
template < class Type >
|
||||
static std::shared_ptr<object> generate(std::unique_ptr<Type>&& t, basic_repository &repo, const std::string &name) {
|
||||
static std::shared_ptr<object> generate(std::unique_ptr<Type>&& t,
|
||||
basic_repository &repo,
|
||||
const std::string &name,
|
||||
const std::string &join_column = "",
|
||||
const std::string &inverse_join_column = "") {
|
||||
const std::type_index ti(typeid(Type));
|
||||
if (repo.has_object_for_type(ti)) {
|
||||
auto obj = repo.object_for_type(ti);
|
||||
@@ -71,6 +75,9 @@ public:
|
||||
std::ignore = repo.provide_object_in_advance(ti, obj);
|
||||
object_generator gen(repo, obj);
|
||||
access::process(gen, *t);
|
||||
if (!join_column.empty() && !inverse_join_column.empty()) {
|
||||
gen.prepare_relation_table(join_column, inverse_join_column);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -111,6 +118,7 @@ private:
|
||||
template<typename ValueType>
|
||||
attribute &emplace_attribute(const char *id, const utils::field_attributes& attr, null_option_type null_option) {
|
||||
auto &ref = object_->attributes_.emplace_back(id, utils::data_type_traits<ValueType>::type(attr.size()), attr, null_option);
|
||||
ref.index_ = object_->attributes_.size() - 1;
|
||||
ref.owner_ = object_;
|
||||
return ref;
|
||||
}
|
||||
@@ -120,9 +128,10 @@ private:
|
||||
void create_fk_constraint(const std::string& name) const;
|
||||
void create_unique_constraint(const std::string& name) const;
|
||||
|
||||
[[nodiscard]] std::list<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
[[nodiscard]] std::vector<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
|
||||
void prepare_primary_key(attribute &ref, utils::identifier &&pk) const;
|
||||
void prepare_primary_key(const attribute &ref, utils::identifier &&pk) const;
|
||||
void prepare_relation_table(const std::string &join_column, const std::string &inverse_join_column) const;
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] std::shared_ptr<object> fk_object() const;
|
||||
@@ -135,7 +144,7 @@ private:
|
||||
|
||||
template<typename ValueType>
|
||||
void object_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
utils::constraints cs = utils::constraints::PrimaryKey;
|
||||
auto cs = utils::constraints::PrimaryKey;
|
||||
if (attr.generator() == utils::generator_type::Identity) {
|
||||
cs |= utils::constraints::Identity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user