Permalink
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/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 5a99887

Please sign in to comment.