diff --git a/docs/releases.md b/docs/releases.md index 580c0f1..ac840dc 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -20,6 +20,7 @@ as the same model can be registered multiple times and `ormar` needs to know fro * Fix minor bug in `order_by` for primary model order bys * Fix in `prefetch_query` for multiple related_names for the same model. * Fix using same `related_name` on different models leading to the same related `Model` overwriting each other, now `ModelDefinitionError` is raised and you need to change the name. +* Fix `order_by` overwriting conditions when multiple joins to the same table applied. ## Docs * Split and cleanup in docs: diff --git a/ormar/queryset/join.py b/ormar/queryset/join.py index ffb07cf..d7b2686 100644 --- a/ormar/queryset/join.py +++ b/ormar/queryset/join.py @@ -400,11 +400,11 @@ class SqlJoin: ) if not current_table_sorted: order = text(f"{alias}_{to_table}.{pkname_alias}") - self.sorted_orders[f"{part}.{pkname_alias}"] = order + self.sorted_orders[f"{alias}.{pkname_alias}"] = order else: order = text(f"{alias}_{to_table}.{pkname_alias}") - self.sorted_orders[f"{part}.{pkname_alias}"] = order + self.sorted_orders[f"{alias}.{pkname_alias}"] = order @staticmethod def get_to_and_from_keys(