More tests for sort query

This commit is contained in:
Konsta Vesterinen
2013-09-19 13:35:25 +03:00
parent 4603f71159
commit 747ff6df99
2 changed files with 10 additions and 0 deletions

View File

@@ -65,6 +65,7 @@ class TestCase(object):
return (
sa.select([sa.func.count(self.Article.id)])
.where(self.Article.category_id == self.Category.id)
.correlate(self.Article.__table__)
.label('article_count')
)

View File

@@ -106,3 +106,12 @@ class TestSortQuery(TestCase):
'ORDER BY (SELECT count(article.id) AS count_1'
) in str(query)
assert ' DESC' in str(query)
def test_sort_by_related_hybrid_property(self):
query = (
self.session.query(self.Article)
.join(self.Article.category)
.correlate(self.Article.__table__)
)
query = sort_query(query, '-category-articles_count')
assert 'ORDER BY (SELECT count(article.id) AS count_1' in str(query)