---
title: "想覆盖之前设置的排序时"
description: "如果你想覆盖之前设置的排序（哪怕是通过 default\\_scope 设置的），请改用 reorder()。"
canonical: https://oozou.com/til/if-you-want-to-override-previously-set-order-25
locale: zh-Hans
date: 2020-10-13
topic: ruby-on-rails
---

# 想覆盖之前设置的排序时

> 如果你想覆盖之前设置的排序（哪怕是通过 default\_scope 设置的），请改用 reorder()。

Published: 2020-10-13 · Topic: [ruby on rails](https://oozou.com/zh-Hans/til-topics/ruby-on-rails) ([markdown](https://oozou.com/zh-Hans/til-topics/ruby-on-rails.md))

如果你想覆盖之前设置的排序（哪怕是通过 default\_scope 设置的），请改用 reorder()。

例如

```ruby
User.order('id ASC').reorder('name DESC')
```

会完全忽略按 id 的排序

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/zh-Hans/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
