diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-08-22 06:43:55 -0700 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-08-22 06:43:55 -0700 |
commit | 042c86d2bf6428f2ebc33b2ca42a29786dfca0fb (patch) | |
tree | b11b0d5959fa4802611234441f5883d0586ad4ec /guides | |
parent | c91f06dd6b507357bb2064b1c19f175cf58a1c29 (diff) | |
parent | e744ac7b5429bf996d5cfa1a23c8f502269b2904 (diff) | |
download | rails-042c86d2bf6428f2ebc33b2ca42a29786dfca0fb.tar.gz rails-042c86d2bf6428f2ebc33b2ca42a29786dfca0fb.tar.bz2 rails-042c86d2bf6428f2ebc33b2ca42a29786dfca0fb.zip |
Merge pull request #11943 from suginoy/ar-order-notation
Add examples of AR order method's hash notation to Rails Guide [ci skip]
Diffstat (limited to 'guides')
-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") |