LoginSignup
28
14

More than 5 years have passed since last update.

Railsでjoinしたテーブルでorderする

Posted at

よく見るサンプルでは、こんな感じだが

Book.joins(:user).order('users.name')

文字列を極力避けたい場合は merge を使うといける。

Book.joins(:user).merge(User.order(:name))

あまり調べても merge の方は出てこない気がするので投稿してみました。

28
14
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
28
14