diff options
author | Sugino Yasuhiro <suginoyasuhiro@gmail.com> | 2013-08-20 11:12:16 +0900 |
---|---|---|
committer | Sugino Yasuhiro <suginoyasuhiro@gmail.com> | 2013-08-22 19:14:51 +0900 |
commit | e744ac7b5429bf996d5cfa1a23c8f502269b2904 (patch) | |
tree | 0e8f46f5d465ec83a3624ac197de808b674611a3 | |
parent | 6846d9146bcbad58b132695907b417592a0f14e0 (diff) | |
download | rails-e744ac7b5429bf996d5cfa1a23c8f502269b2904.tar.gz rails-e744ac7b5429bf996d5cfa1a23c8f502269b2904.tar.bz2 rails-e744ac7b5429bf996d5cfa1a23c8f502269b2904.zip |
Add examples of AR order method's hash notation to Rails Guide [ci skip]
-rw-r--r-- | guides/source/active_record_querying.md | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index ce571c6f96..ba0dc6d9eb 100644 --- a/guides/source/active_record_querying.md +++ b/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") |