diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-03-24 10:55:29 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-03-24 10:55:29 -0400 |
| commit | bdcaa0f6ca580b54b9c25178441fcbe8f2a4e387 (patch) | |
| tree | 61a80475ad22f83067ab0b2fe1df65b709f3a2c1 /test/ext | |
| parent | 04545727d4117db51786189e591b1777bde1a40b (diff) | |
| download | sqlalchemy-bdcaa0f6ca580b54b9c25178441fcbe8f2a4e387.tar.gz | |
- The "auto-attach" feature of constraints such as :class:`.UniqueConstraint`
and :class:`.CheckConstraint` has been further enhanced such that
when the constraint is associated with non-table-bound :class:`.Column`
objects, the constraint will set up event listeners with the
columns themselves such that the constraint auto attaches at the
same time the columns are associated with the table. This in particular
helps in some edge cases in declarative but is also of general use.
fixes #3341
Diffstat (limited to 'test/ext')
| -rw-r--r-- | test/ext/declarative/test_inheritance.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/ext/declarative/test_inheritance.py b/test/ext/declarative/test_inheritance.py index 6ea37e4d3..2ecee99fd 100644 --- a/test/ext/declarative/test_inheritance.py +++ b/test/ext/declarative/test_inheritance.py @@ -485,6 +485,41 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): ).one(), Engineer(name='vlad', primary_language='cobol')) + def test_single_constraint_on_sub(self): + """test the somewhat unusual case of [ticket:3341]""" + + class Person(Base, fixtures.ComparableEntity): + + __tablename__ = 'people' + id = Column(Integer, primary_key=True, + test_needs_autoincrement=True) + name = Column(String(50)) + discriminator = Column('type', String(50)) + __mapper_args__ = {'polymorphic_on': discriminator} + + class Engineer(Person): + + __mapper_args__ = {'polymorphic_identity': 'engineer'} + primary_language = Column(String(50)) + + __hack_args_one__ = sa.UniqueConstraint( + Person.name, primary_language) + __hack_args_two__ = sa.CheckConstraint( + Person.name != primary_language) + + uq = [c for c in Person.__table__.constraints + if isinstance(c, sa.UniqueConstraint)][0] + ck = [c for c in Person.__table__.constraints + if isinstance(c, sa.CheckConstraint)][0] + eq_( + list(uq.columns), + [Person.__table__.c.name, Person.__table__.c.primary_language] + ) + eq_( + list(ck.columns), + [Person.__table__.c.name, Person.__table__.c.primary_language] + ) + @testing.skip_if(lambda: testing.against('oracle'), "Test has an empty insert in it at the moment") def test_columns_single_inheritance_conflict_resolution(self): |
