Fix sorting for aliased
This commit is contained in:

committed by
Konsta Vesterinen

parent
4cde5438a5
commit
46038334d2
@@ -672,6 +672,9 @@ def get_descriptor(entity, attr):
|
|||||||
else:
|
else:
|
||||||
# Handle synonyms, relationship properties and hybrid
|
# Handle synonyms, relationship properties and hybrid
|
||||||
# properties
|
# properties
|
||||||
|
|
||||||
|
if isinstance(entity, sa.orm.util.AliasedClass):
|
||||||
|
return getattr(entity, attr)
|
||||||
try:
|
try:
|
||||||
return getattr(mapper.class_, attr)
|
return getattr(mapper.class_, attr)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@@ -75,6 +75,15 @@ class TestCase(object):
|
|||||||
__tablename__ = 'category'
|
__tablename__ = 'category'
|
||||||
id = sa.Column(sa.Integer, primary_key=True)
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
name = sa.Column(sa.Unicode(255))
|
name = sa.Column(sa.Unicode(255))
|
||||||
|
title = sa.Column(sa.Unicode(255))
|
||||||
|
|
||||||
|
@hybrid_property
|
||||||
|
def full_name(self):
|
||||||
|
return u'%s %s' % (self.title, self.name)
|
||||||
|
|
||||||
|
@full_name.expression
|
||||||
|
def full_name(self):
|
||||||
|
return sa.func.concat(self.title, ' ', self.name)
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def articles_count(self):
|
def articles_count(self):
|
||||||
|
@@ -211,6 +211,23 @@ class TestSortQueryRelationshipCounts(TestCase):
|
|||||||
query = sort_query(query, '-categories-articles_count')
|
query = sort_query(query, '-categories-articles_count')
|
||||||
assert_contains('ORDER BY (SELECT count(article.id) AS count_1', query)
|
assert_contains('ORDER BY (SELECT count(article.id) AS count_1', query)
|
||||||
|
|
||||||
|
def test_aliased_concat_hybrid_property(self):
|
||||||
|
alias = sa.orm.aliased(
|
||||||
|
self.Category,
|
||||||
|
name='aliased'
|
||||||
|
)
|
||||||
|
query = (
|
||||||
|
self.session.query(self.Article)
|
||||||
|
.outerjoin(alias, self.Article.category)
|
||||||
|
.options(
|
||||||
|
sa.orm.contains_eager(self.Article.category, alias=alias)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
query = sort_query(query, 'aliased-full_name')
|
||||||
|
assert_contains(
|
||||||
|
'concat(aliased.title, :param_1, aliased.name)', query
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestSortQueryWithPolymorphicInheritance(TestCase):
|
class TestSortQueryWithPolymorphicInheritance(TestCase):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user