Browse files

Merge pull request #11943 from suginoy/ar-order-notation

Add examples of AR order method's hash notation to Rails Guide [ci skip]
  • Loading branch information...
1 parent a3bf24a commit 5a9988762dd060b54898d03ece76cd582f9e3448 @senny senny committed Aug 22, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 guides/source/
@@ -524,12 +524,18 @@ To retrieve records from the database in a specific order, you can use the `orde
For example, if you're getting a set of records and want to order them in ascending order by the `created_at` field in your table:
+# OR
You could specify `ASC` or `DESC` as well:
+Client.order(created_at: :desc)
+# OR
+Client.order(created_at: :asc)
+# OR
Client.order("created_at DESC")
# OR
Client.order("created_at ASC")
@@ -538,6 +544,10 @@ Client.order("created_at ASC")
Or ordering by multiple fields:
+Client.order(orders_count: :asc, created_at: :desc)
+# OR
+Client.order(:orders_count, created_at: :desc)
+# OR
Client.order("orders_count ASC, created_at DESC")
# OR
Client.order("orders_count ASC", "created_at DESC")

0 comments on commit 5a99887

Please sign in to comment.