Skip to content

Commit

Permalink
document Active Record's reverse_order method
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaydev authored and fxn committed Jun 23, 2011
1 parent 741a417 commit ae8d53e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions railties/guides/source/active_record_querying.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The methods are:
* +group+ * +group+
* +order+ * +order+
* +reorder+ * +reorder+
* +reverse_order+
* +limit+ * +limit+
* +offset+ * +offset+
* +joins+ * +joins+
Expand Down Expand Up @@ -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 SELECT * FROM posts WHERE id = 10 ORDER BY posted_at DESC
</sql> </sql>


h4. +reverse_order+

The +reverse_order+ method reverses the ordering clause if specified.

<ruby>
Client.where("orders_count > 10").order(:name).reverse_order
</ruby>

The SQL that would be executed:
<sql>
SELECT * FROM clients WHERE orders_count > 10 ORDER BY name DESC
</sql>

If no ordering clause is specified in the query, the +reverse_order+ orders by the primary key in reverse order.

<ruby>
Client.where("orders_count > 10").reverse_order
</ruby>

The SQL that would be executed:
<sql>
SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC
</sql>

This method accepts *no* arguments.

h3. Readonly Objects 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. 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.
Expand Down

0 comments on commit ae8d53e

Please sign in to comment.