Snippets Collections
user = User.first

result = user.user_books.in_order_of(:status, %w[to_read currently_reading read])

=> #<ActiveRecord::Relation [#<UserBook id: 3, user_id: 1, status: "to_read">, #<UserBook id: 4, user_id: 1, status: "to_read">, #<UserBook id: 5, user_id: 1, status: "currently_reading">, #<UserBook id: 6, user_id: 1, status: "read">]>
star

Tue Nov 30 2021 16:35:12 GMT+0000 (UTC) https://blog.saeloun.com/2021/10/05/rails-7-activerecord-adds-in_order_of-method

#sql #arel #query

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension