diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-01-02 18:51:49 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-01-02 18:51:49 -0500 |
commit | 8a7fdd4e5cf5e4d9ba71c66a06bcba6b1054cfef (patch) | |
tree | e4ce11d8516235d6df37ca91ea40bf31f8e6edc1 /test/ext/declarative/test_basic.py | |
parent | ca8fca63916897f1bbc2fa4f1ee440c6b5d9a88a (diff) | |
download | sqlalchemy-8a7fdd4e5cf5e4d9ba71c66a06bcba6b1054cfef.tar.gz |
- A quasi-regression where apparently in 0.8 you can set a class-level
attribute on declarative to simply refer directly to an :class:`.InstrumentedAttribute`
on a superclass or on the class itself, and it
acts more or less like a synonym; in 0.9, this fails to set up enough
bookkeeping to keep up with the more liberalized backref logic
from :ticket:`2789`. Even though this use case was never directly
considered, it is now detected by declarative at the "setattr()" level
as well as when setting up a subclass, and the mirrored/renamed attribute
is now set up as a :func:`.synonym` instead. [ticket:2900]
Diffstat (limited to 'test/ext/declarative/test_basic.py')
-rw-r--r-- | test/ext/declarative/test_basic.py | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 0d213fce3..1f14d8164 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -11,7 +11,7 @@ from sqlalchemy.testing.schema import Table, Column from sqlalchemy.orm import relationship, create_session, class_mapper, \ joinedload, configure_mappers, backref, clear_mappers, \ deferred, column_property, composite,\ - Session + Session, properties from sqlalchemy.testing import eq_ from sqlalchemy.util import classproperty, with_metaclass from sqlalchemy.ext.declarative import declared_attr, AbstractConcreteBase, \ @@ -792,6 +792,64 @@ class DeclarativeTest(DeclarativeTestBase): eq_(a1, Address(email='two')) eq_(a1.user, User(name='u1')) + def test_alt_name_attr_subclass_column_inline(self): + # [ticket:2900] + class A(Base): + __tablename__ = 'a' + id = Column('id', Integer, primary_key=True) + data = Column('data') + + class ASub(A): + brap = A.data + assert ASub.brap.property is A.data.property + assert isinstance(ASub.brap.original_property, properties.SynonymProperty) + + def test_alt_name_attr_subclass_relationship_inline(self): + # [ticket:2900] + class A(Base): + __tablename__ = 'a' + id = Column('id', Integer, primary_key=True) + b_id = Column(Integer, ForeignKey('b.id')) + b = relationship("B", backref="as_") + + class B(Base): + __tablename__ = 'b' + id = Column('id', Integer, primary_key=True) + + configure_mappers() + class ASub(A): + brap = A.b + assert ASub.brap.property is A.b.property + assert isinstance(ASub.brap.original_property, properties.SynonymProperty) + ASub(brap=B()) + + def test_alt_name_attr_subclass_column_attrset(self): + # [ticket:2900] + class A(Base): + __tablename__ = 'a' + id = Column('id', Integer, primary_key=True) + data = Column('data') + A.brap = A.data + assert A.brap.property is A.data.property + assert isinstance(A.brap.original_property, properties.SynonymProperty) + + def test_alt_name_attr_subclass_relationship_attrset(self): + # [ticket:2900] + class A(Base): + __tablename__ = 'a' + id = Column('id', Integer, primary_key=True) + b_id = Column(Integer, ForeignKey('b.id')) + b = relationship("B", backref="as_") + A.brap = A.b + class B(Base): + __tablename__ = 'b' + id = Column('id', Integer, primary_key=True) + + assert A.brap.property is A.b.property + assert isinstance(A.brap.original_property, properties.SynonymProperty) + A(brap=B()) + + def test_eager_order_by(self): class Address(Base, fixtures.ComparableEntity): |