Skip to content

Commit d5a11f3

Browse files
committed
Fixed a bug that was causing columns that were part of PKs not to be
removed by the user (issue #2016)
1 parent e3a1bda commit d5a11f3

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

libs/libcore/src/baseobject.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,8 +1633,16 @@ void BaseObject::updateDependencies()
16331633

16341634
void BaseObject::updateDependencies(const std::vector<BaseObject *> &dep_objs, const std::vector<BaseObject *> &old_deps)
16351635
{
1636-
for(auto &old_dep : old_deps)
1637-
unsetDependency(old_dep);
1636+
/* If the custom list of old dependencies is emtpy, by default,
1637+
* the current dependencies will be unset */
1638+
if(old_deps.empty())
1639+
clearDependencies();
1640+
// Otherwise we unset only the dependencies provided in old_deps
1641+
else
1642+
{
1643+
for(auto &old_dep : old_deps)
1644+
unsetDependency(old_dep);
1645+
}
16381646

16391647
std::vector<BaseObject *> aux_deps = {
16401648
schema, tablespace, owner, collation

libs/libcore/src/baseobject.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class __libcore BaseObject {
297297
/*! \brief This version, called inside updateDependencies(), just run through the provided
298298
* dep_objs list and sets the dependency link between the "this" object and the items
299299
* in the list. Additionally, a list of dependencies that must be undone can be provided.
300+
* This method clears the old dependencies by default if old_deps is empty.
300301
*
301302
* The dependency link breaking operation made using old_deps runs first before creating the
302303
* dependency link using the objects in dep_objs.
@@ -683,9 +684,15 @@ class __libcore BaseObject {
683684
bool isDependingOn(BaseObject *dep_obj);
684685

685686
/*! \brief Updates the dependencies list based upon the current relationship between
686-
* the "this" object and its dependencies. NOTE: this method must be called only in specific
687-
* points of the code (currently only in the operator = due to the need in OperationList class )
688-
* because it can be expensive in terms of processing if lots of objects calls it */
687+
* the "this" object and its dependencies. This method clears the old dependencies
688+
* relationships and creates other ones.
689+
*
690+
* NOTE: this version of the method only produces a dependency relationship between the
691+
* schema, tablespace, owner and collation. Derived classes must reimplement thi one and include
692+
* other dependency objects, e.g., data types, functions, and etc.
693+
*
694+
* NOTE: this method must be called only in specific points of the code because it can be expensive
695+
* in terms of processing if lots of objects calls it. */
689696
virtual void updateDependencies();
690697

691698
friend class DatabaseModel;

libs/libgui/src/dbobjects/tablewidget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,8 @@ void TableWidget::applyConfiguration()
10671067
* Duplicated columns are discarded by the method Constraint::addColumn */
10681068
for(Column *col : pk_cols)
10691069
pk->addColumn(col, Constraint::SourceCols);
1070+
1071+
pk->updateDependencies();
10701072
}
10711073
}
10721074
else if(pk_cols.empty() && pk && !pk->isAddedByRelationship())

0 commit comments

Comments
 (0)