Skip to content
Browse files

Add examples of AR order method's hash notation to Rails Guide [ci skip]

  • Loading branch information...
1 parent 6846d91 commit e744ac7b5429bf996d5cfa1a23c8f502269b2904 @suginoy suginoy committed Aug 20, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 guides/source/active_record_querying.md
View
10 guides/source/active_record_querying.md
@@ -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:
```ruby
+Client.order(:created_at)
+# OR
Client.order("created_at")
```
You could specify `ASC` or `DESC` as well:
```ruby
+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:
```ruby
+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 e744ac7

Please sign in to comment.
Something went wrong with that request. Please try again.