diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-20 12:24:40 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-20 15:59:37 -0400 |
| commit | 6abbda34ebb2c154ccae12d749968fe72f27f372 (patch) | |
| tree | ed8d093e3153e0866107e5222a176b464ecd2bd7 /test | |
| parent | fe35828eefc00e12e01df25f6fd942eecde1a686 (diff) | |
| download | sqlalchemy-6abbda34ebb2c154ccae12d749968fe72f27f372.tar.gz | |
Add ColumnProperty.Comparator.expressions
Added an accessor :attr:`.ColumnProperty.Comparator.expressions` which
provides access to the group of columns mapped under a multi-column
:class:`.ColumnProperty` attribute.
Fixes: #5262
Change-Id: I44cf53ff0e6cf76a0c90eee4638ca96da3df8088
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/inheritance/test_basic.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index cb4e70ecb..02addc6f5 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -131,6 +131,50 @@ class O2MTest(fixtures.MappedTest): eq_(result[1].parent_foo.data, "foo #1") +class ColExpressionsTest(fixtures.DeclarativeMappedTest): + __backend__ = True + + @classmethod + def setup_classes(cls): + Base = cls.DeclarativeBasic + + class A(Base): + __tablename__ = "a" + id = Column( + Integer, primary_key=True, test_needs_autoincrement=True + ) + type = Column(String(10)) + __mapper_args__ = { + "polymorphic_on": type, + "polymorphic_identity": "a", + } + + class B(A): + __tablename__ = "b" + id = Column(ForeignKey("a.id"), primary_key=True) + data = Column(Integer) + __mapper_args__ = {"polymorphic_identity": "b"} + + @classmethod + def insert_data(cls, connection): + A, B = cls.classes("A", "B") + s = Session(connection) + + s.add_all([B(data=5), B(data=7)]) + s.commit() + + def test_group_by(self): + B = self.classes.B + s = Session() + + rows = ( + s.query(B.id.expressions[0], B.id.expressions[1], func.sum(B.data)) + .group_by(*B.id.expressions) + .all() + ) + eq_(rows, [(1, 1, 5), (2, 2, 7)]) + + class PolyExpressionEagerLoad(fixtures.DeclarativeMappedTest): run_setup_mappers = "once" __dialect__ = "default" |
