LoginSignup
5
4

More than 5 years have passed since last update.

複数条件の default_scope を設定する

Posted at

order_by と where を default_scope に設定しようと思って


default_scope { where(active: true), order(product_id: :desc, id: :desc} }

と書いたらエラーになった… 適当に書いてもダメですね orz。

公式ドキュメント を見たところ、default_scope を複数記述すると merge されるとのことで、以下で意図通りになった。

default_scope { where(active: true) }
default_scope { order(product_id: :desc, id: :desc) }
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4