Skip to content

Commit

Permalink
Add test case for order by translated property
Browse files Browse the repository at this point in the history
  • Loading branch information
kvesteri committed Jan 13, 2015
1 parent 869d2f9 commit 17d5e61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ArticleTranslation(translation_base(Article)):
content = sa.Column(sa.UnicodeText)

self.Article = Article
self.ArticleTranslation = ArticleTranslation

def create_article(self):
article = self.Article(name=u'Something', content=u'Something')
Expand Down
19 changes: 19 additions & 0 deletions tests/test_join_expressions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import sqlalchemy as sa
from tests import DeclarativeTestCase, ClassicTestCase


Expand All @@ -14,6 +15,24 @@ def test_current_translation_as_expression(self):
in str(query)
)

def test_order_by_translation(self):
self.session.add(self.Article(name=u'cbc'))
self.session.add(self.Article(name=u'abc'))
self.session.add(self.Article(name=u'bbc'))
self.session.commit()

current_translation = sa.orm.aliased(self.Article.current_translation)
articles = (
self.session.query(self.Article)
.join(current_translation, self.Article.current_translation)
.options(sa.orm.contains_eager(
self.Article.current_translation, alias=current_translation)
)
.order_by(current_translation.name)
).all()
names = [a.name for a in articles]
assert names == ['abc', 'bbc', 'cbc']

def test_fallback_locale_as_expression(self):
query = (
self.session.query(self.Article)
Expand Down

0 comments on commit 17d5e61

Please sign in to comment.