Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cubes/query/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,16 +1009,16 @@ def all_attributes(self):
@property
def natural_order(self):
"""Return a natural order for the drill-down. This order can be merged
with user-specified order. Returns a list of tuples:
(`attribute_name`, `order`)."""
with user-specified order. Returns a dictionary where keys are
attribute ref and vales are directions."""

order = []
order = {}

for item in self.drilldown:
for level in item.levels:
lvl_attr = level.order_attribute or level.key
lvl_order = level.order or 'asc'
order.append((lvl_attr, lvl_order))
order[lvl_attr.ref] = lvl_order

return order

Expand Down
2 changes: 1 addition & 1 deletion cubes/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def order_query(statement, order, natural_order=None, labels=None):
# Collect natural order for selected columns that have no explicit
# ordering
for (name, column) in columns.items():
if name in natural_order and name not in order_by:
if name in natural_order and name not in final_order.keys():
final_order[name] = order_column(column, natural_order[name])

statement = statement.order_by(*final_order.values())
Expand Down