Skip to content

Commit

Permalink
Add examples of AR order method's hash notation to Rails Guide [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
suginoy committed Aug 22, 2013
1 parent 6846d91 commit e744ac7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions guides/source/active_record_querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit e744ac7

Please sign in to comment.