diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-01-31 19:14:08 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-01-31 19:14:08 -0500 |
| commit | 6b3ecd14eae1a557cffd19da6c82d967586a6d74 (patch) | |
| tree | 362fa6f32cb2f7a0f4d32722259ef573b222cdd2 /test | |
| parent | b360dbf7ebb7cc5bb290847fdd9818d205244a94 (diff) | |
| download | sqlalchemy-6b3ecd14eae1a557cffd19da6c82d967586a6d74.tar.gz | |
- Added a new parameter :paramref:`.Operators.op.is_comparison`. This
flag allows a custom op from :meth:`.Operators.op` to be considered
as a "comparison" operator, thus usable for custom
:paramref:`.relationship.primaryjoin` conditions.
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_relationships.py | 39 | ||||
| -rw-r--r-- | test/sql/test_operators.py | 10 |
2 files changed, 49 insertions, 0 deletions
diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index 8f7e2bd55..ccd54284a 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -1517,6 +1517,45 @@ class TypedAssociationTable(fixtures.MappedTest): assert t3.count().scalar() == 1 +class CustomOperatorTest(fixtures.MappedTest, AssertsCompiledSQL): + """test op() in conjunction with join conditions""" + + run_create_tables = run_deletes = None + + __dialect__ = 'default' + + @classmethod + def define_tables(cls, metadata): + Table('a', metadata, + Column('id', Integer, primary_key=True), + Column('foo', String(50)) + ) + Table('b', metadata, + Column('id', Integer, primary_key=True), + Column('foo', String(50)) + ) + + def test_join_on_custom_op(self): + class A(fixtures.BasicEntity): + pass + class B(fixtures.BasicEntity): + pass + + mapper(A, self.tables.a, properties={ + 'bs': relationship(B, + primaryjoin=self.tables.a.c.foo.op( + '&*', is_comparison=True + )(foreign(self.tables.b.c.foo)), + viewonly=True + ) + }) + mapper(B, self.tables.b) + self.assert_compile( + Session().query(A).join(A.bs), + "SELECT a.id AS a_id, a.foo AS a_foo FROM a JOIN b ON a.foo &* b.foo" + ) + + class ViewOnlyHistoryTest(fixtures.MappedTest): @classmethod def define_tables(cls, metadata): diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 670d088d2..79b0a717b 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -1585,3 +1585,13 @@ class ComposedLikeOperatorsTest(fixtures.TestBase, testing.AssertsCompiledSQL): dialect=mysql.dialect() ) +class CustomOpTest(fixtures.TestBase): + def test_is_comparison(self): + c = column('x') + c2 = column('y') + op1 = c.op('$', is_comparison=True)(c2).operator + op2 = c.op('$', is_comparison=False)(c2).operator + + assert operators.is_comparison(op1) + assert not operators.is_comparison(op2) + |
