diff --git a/cubes/query/browser.py b/cubes/query/browser.py index c547abaa..20d36692 100644 --- a/cubes/query/browser.py +++ b/cubes/query/browser.py @@ -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 diff --git a/cubes/sql/utils.py b/cubes/sql/utils.py index 10030c00..ddfcc872 100644 --- a/cubes/sql/utils.py +++ b/cubes/sql/utils.py @@ -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())