From 5eac40bb7508947f181d8eb6bdff547ec3b4ef36 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 20 Jun 2011 02:12:21 +0530 Subject: document Active Record's reverse_order method --- .../guides/source/active_record_querying.textile | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index b4ce60fcaa..e3871a3c34 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -57,6 +57,7 @@ The methods are: * +group+ * +order+ * +reorder+ +* +reverse_order+ * +limit+ * +offset+ * +joins+ @@ -550,6 +551,32 @@ In case the +reorder+ clause is not used, the SQL executed would be: SELECT * FROM posts WHERE id = 10 ORDER BY posted_at DESC +h4. +reverse_order+ + +The +reverse_order+ method reverses the ordering clause if specified. + + +Client.where("orders_count > 10").order(:name).reverse_order + + +The SQL that would be executed: + +SELECT * FROM clients WHERE orders_count > 10 ORDER BY name DESC + + +If no ordering clause is specified in the query, the +reverse_order+ orders by the primary key in reverse order. + + +Client.where("orders_count > 10").reverse_order + + +The SQL that would be executed: + +SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC + + +This method accepts *no* arguments. + h3. Readonly Objects Active Record provides +readonly+ method on a relation to explicitly disallow modification or deletion of any of the returned object. Any attempt to alter or destroy a readonly record will not succeed, raising an +ActiveRecord::ReadOnlyRecord+ exception. -- cgit v1.2.3