3

How do I set a default order_by clause in a class definition in SQLAlchemy, so that any query against this class will automatically have this clause?

The ORM docs for order_by talk about mapper.order_by but says that this is deprecated, and also mentions overriding existing order_by settings but without saying how these settings might get there.

user1235777
  • 609
  • 7
  • 24
  • 7
    The documentation tells you to use `Query.order_by()` instead - which means there is no practical way to avoid ordering on query level. This makes a lot of sense anyway, as ordering happens on database and consumes resources. A default clause would cause your database to sort even those results you do not need to have sorted. – Hannu Jan 10 '18 at 15:33
  • 1
    Related: https://stackoverflow.com/questions/14361264/the-default-sorting-criteria-of-sqlalchemy. – Ilja Everilä Jan 10 '18 at 19:39

0 Answers0