summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-01-20 18:14:02 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-01-20 18:14:02 -0500
commit417aeaf1453c67130fb8f1a2bb21c38e6795ce25 (patch)
tree0dd3a43dd183e9619a7f0cc84b8a5623495d84e5 /lib/sqlalchemy/sql/schema.py
parent49f1807f8f2acea5494fa77d217dce813a933147 (diff)
downloadsqlalchemy-417aeaf1453c67130fb8f1a2bb21c38e6795ce25.tar.gz
- further refine this so that the ordering of columns is maintained as
sent to the primary key constraint; existing tests in the PG dialect confirm this.
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 09f52f8a7..ba38b5070 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -2623,9 +2623,12 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
c.primary_key = True
self.columns.extend(table_pks)
- def _reload(self):
- """repopulate this :class:`.PrimaryKeyConstraint` based on the current
- columns marked with primary_key=True in the table.
+ def _reload(self, columns):
+ """repopulate this :class:`.PrimaryKeyConstraint` given
+ a set of columns.
+
+ Existing columns in the table that are marked as primary_key=True
+ are maintained.
Also fires a new event.
@@ -2633,14 +2636,20 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
:class:`.PrimaryKeyConstraint` object on the parent
:class:`.Table` object without actually replacing the object.
+ The ordering of the given list of columns is also maintained; these
+ columns will be appended to the list of columns after any which
+ are already present.
+
"""
- # clear out the columns collection; we will re-populate
- # based on current primary_key flags
- self.columns.clear()
+ # set the primary key flag on new columns.
+ # note any existing PK cols on the table also have their
+ # flag still set.
+ for col in columns:
+ col.primary_key = True
+
+ self.columns.extend(columns)
- # fire a new event; this will add all existing
- # primary key columns based on the flag.
self._set_parent_with_dispatch(self.table)
def _replace(self, col):