diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-24 16:08:35 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-24 16:08:35 -0400 |
commit | f69ccd193b5f1bfe4f2f50e93fe912ceac1af66e (patch) | |
tree | fa618540df1d0611855e971720e98604511b9ffe /lib/sqlalchemy/schema.py | |
parent | ae90ba28e85835c278c64d5894ee1a983d11e400 (diff) | |
download | sqlalchemy-f69ccd193b5f1bfe4f2f50e93fe912ceac1af66e.tar.gz |
- [bug] All of UniqueConstraint, ForeignKeyConstraint,
CheckConstraint, and PrimaryKeyConstraint will
attach themselves to their parent table automatically
when they refer to a Table-bound Column object directly
(i.e. not just string column name), and refer to
one and only one Table. Prior to 0.8 this behavior
occurred for UniqueConstraint and PrimaryKeyConstraint,
but not ForeignKeyConstraint or CheckConstraint.
[ticket:2410]
Diffstat (limited to 'lib/sqlalchemy/schema.py')
-rw-r--r-- | lib/sqlalchemy/schema.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 0a22d8855..f710ae736 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1980,6 +1980,14 @@ class CheckConstraint(Constraint): self.sqltext = expression._literal_as_text(sqltext) if table is not None: self._set_parent_with_dispatch(table) + else: + cols = sqlutil.find_columns(self.sqltext) + tables = set([c.table for c in cols + if c.table is not None]) + if len(tables) == 1: + self._set_parent_with_dispatch( + tables.pop()) + def __visit_name__(self): if isinstance(self.parent, Table): @@ -2083,6 +2091,11 @@ class ForeignKeyConstraint(Constraint): if table is not None: self._set_parent_with_dispatch(table) + elif columns and \ + isinstance(columns[0], Column) and \ + columns[0].table is not None: + self._set_parent_with_dispatch(columns[0].table) + @property def columns(self): |