---
title: "想覆寫先前設定的排序時"
description: "如果你想覆寫先前設定的排序（即使是透過 default\\_scope 設定的），請改用 reorder()。"
canonical: https://oozou.com/til/if-you-want-to-override-previously-set-order-25
locale: zh-Hant
date: 2020-10-13
topic: ruby-on-rails
---

# 想覆寫先前設定的排序時

> 如果你想覆寫先前設定的排序（即使是透過 default\_scope 設定的），請改用 reorder()。

Published: 2020-10-13 · Topic: [ruby on rails](https://oozou.com/zh-Hant/til-topics/ruby-on-rails) ([markdown](https://oozou.com/zh-Hant/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-Hant/contact

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