0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails4 orderの罠

Posted at

Rails4からOrderにハッシュ渡せて快適!という記事はいっぱいありますが、複数指定する場合、

User.order(:name, created_at: :desc)

SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."created_at" DESC

なら問題ないのですが(大抵の記事はこっちしか書いてない)、逆にすると

User.order(created_at: :desc, :name)

syntax error, unexpected ')', expecting =>

あれ?

User.order(created_at: :desc, name: :asc)

SELECT "users".* FROM "users" ORDER BY "users"."created_at" DESC, "users"."name" ASC

こうしないとダメみたい

0
0
2

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?