delete many to many progress
This commit is contained in:
parent
cea7b97f2b
commit
12f8590634
|
|
@ -105,6 +105,7 @@ public:
|
|||
void on_foreign_key(const char *id, Pointer &/*x*/) {
|
||||
const auto type = pk_type_determinator::determine<typename Pointer::value_type>();
|
||||
auto &ref = object_->attributes_.emplace_back(id, type, utils::constraints::ForeignKey, null_option_type::NotNull);
|
||||
ref.index_ = object_->attributes_.size() - 1;
|
||||
ref.owner_ = object_;
|
||||
}
|
||||
template<class ContainerType>
|
||||
|
|
|
|||
|
|
@ -373,7 +373,9 @@ void schema_observer<Type>::on_attach(const object::repository_node &node, const
|
|||
auto producer = std::make_unique<query_object_resolver_producer<Type>>(schema_, it->second.table(), it->second.node().info().primary_key_attribute()->name());
|
||||
schema_.resolver_producers_[typeid(Type)] = std::move(producer);
|
||||
} else {
|
||||
object::join_columns_collector collector;
|
||||
const auto it = schema_.insert_relation_table(typeid(Type), node);
|
||||
// auto producer = std::make_unique<query_object_resolver_producer<Type>>(schema_, it->second.table(), it->second.node().info().primary_key_attribute()->name());
|
||||
// schema_.resolver_producers_[typeid(Type)] = std::move(producer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public:
|
|||
table(const char *name); // NOLINT(*-explicit-constructor)
|
||||
table(const std::string& name); // NOLINT(*-explicit-constructor)
|
||||
table(const std::string& name, const std::vector<table_column>& columns);
|
||||
table(const std::string& name, const std::vector<table_column>& columns, const std::string& join_column, const std::string& inverse_join_column);
|
||||
table(const table& other);
|
||||
table& operator=(const table& other);
|
||||
table(table&& other) noexcept;
|
||||
|
|
@ -44,11 +45,11 @@ public:
|
|||
[[nodiscard]] bool has_primary_key() const;
|
||||
|
||||
[[nodiscard]] const table_column* primary_key_column() const;
|
||||
[[nodiscard]] const std::string& join_column_name() const;
|
||||
[[nodiscard]] const std::string& inverse_join_column_name() const;
|
||||
[[nodiscard]] const table_column* join_column() const;
|
||||
[[nodiscard]] const table_column* inverse_join_column() const;
|
||||
|
||||
protected:
|
||||
table(std::string name, std::string alias, const std::vector<table_column>& columns);
|
||||
table(std::string name, std::string alias, const std::vector<table_column>& columns);
|
||||
|
||||
private:
|
||||
friend table_column;
|
||||
|
|
@ -60,8 +61,8 @@ private:
|
|||
std::vector<table_column> columns_;
|
||||
|
||||
int pk_column_index_{-1};
|
||||
std::string join_column_name_;
|
||||
std::string inverse_join_column_name_;
|
||||
int join_column_index_{-1};
|
||||
int inverse_join_column_index_{-1};
|
||||
};
|
||||
|
||||
template<typename Type = table>
|
||||
|
|
|
|||
|
|
@ -61,5 +61,17 @@ schema::iterator schema::insert_table(const std::type_index &ti, const object::r
|
|||
}
|
||||
|
||||
basic_schema::iterator schema::insert_relation_table(const std::type_index &ti, const object::repository_node &node) {
|
||||
std::vector<table_column> columns;
|
||||
const auto* attr = node.info().object()->join_attribute();
|
||||
if (attr == nullptr) {
|
||||
return schema_nodes_.end();
|
||||
}
|
||||
columns.emplace_back(nullptr, attr->name(), attr->type(), attr->attributes());
|
||||
attr = node.info().object()->inverse_join_attribute();
|
||||
if (attr == nullptr) {
|
||||
return schema_nodes_.end();
|
||||
}
|
||||
columns.emplace_back(nullptr, attr->name(), attr->type(), attr->attributes());
|
||||
return schema_nodes_.insert({ti, schema_node{table(node.name(), columns, node.info().object()->join_attribute()->name(), node.info().object()->inverse_join_attribute()->name()), nullptr, node}}).first;
|
||||
}
|
||||
} // namespace matador::query
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ query_contexts to_query_contexts(const schema_node& node, const sql::dialect &d)
|
|||
.from(node.name())
|
||||
.where(*node.table().primary_key_column() == _)
|
||||
.compile(d);
|
||||
} else {
|
||||
queries.delete_one = query::remove()
|
||||
.from(node.name())
|
||||
.where(*node.table().join_column() == _ && *node.table().inverse_join_column() == _)
|
||||
.compile(d);
|
||||
}
|
||||
// INSERT one
|
||||
std::vector<table_column> columns;
|
||||
|
|
@ -39,7 +44,7 @@ query_contexts to_query_contexts(const schema_node& node, const sql::dialect &d)
|
|||
}
|
||||
columns.push_back(col);
|
||||
}
|
||||
if (node.pk_generator().type() == utils::generator_type::Identity) {
|
||||
if (node.table().has_primary_key() && node.pk_generator().type() == generator_type::Identity) {
|
||||
queries.insert = query::insert()
|
||||
.into(node.name(), columns)
|
||||
.values(generator::placeholders(columns.size()))
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ table::table(const std::string& name, const std::vector<table_column> &columns)
|
|||
: table(name, name, columns) {
|
||||
}
|
||||
|
||||
table::table(const std::string& name, const std::vector<table_column>& columns, const std::string& join_column, const std::string& inverse_join_column)
|
||||
: table(name, name, columns)
|
||||
, join_column_index_(column_by_name(*this, join_column))
|
||||
, inverse_join_column_index_(column_by_name(*this, inverse_join_column)){
|
||||
}
|
||||
|
||||
table::table(std::string name, std::string alias, const std::vector<table_column> &columns)
|
||||
: name_(std::move(name))
|
||||
, alias_(std::move(alias))
|
||||
|
|
@ -121,11 +127,11 @@ const table_column* table::primary_key_column() const {
|
|||
return pk_column_index_ > -1 ? &columns_.at(pk_column_index_) : nullptr;
|
||||
}
|
||||
|
||||
const std::string &table::join_column_name() const {
|
||||
return join_column_name_;
|
||||
const table_column* table::join_column() const {
|
||||
return join_column_index_ > -1 ? &columns_.at(join_column_index_) : nullptr;
|
||||
}
|
||||
|
||||
const std::string &table::inverse_join_column_name() const {
|
||||
return inverse_join_column_name_;
|
||||
const table_column* table::inverse_join_column() const {
|
||||
return inverse_join_column_index_ > -1 ? &columns_.at(inverse_join_column_index_) : nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue