aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-06-26 17:06:19 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2011-06-26 17:06:19 +0530
commit798aa881af53075ed6bbc73d19556b001af68ab7 (patch)
tree1692b1c2dabe6cda564bfe834a9b83e8a7261e17 /railties/guides
parent5f5feb27b6a70a3dda36e6554d405d8d64042560 (diff)
downloadrails-798aa881af53075ed6bbc73d19556b001af68ab7.tar.gz
rails-798aa881af53075ed6bbc73d19556b001af68ab7.tar.bz2
rails-798aa881af53075ed6bbc73d19556b001af68ab7.zip
minor indentation fixes on a6293ff
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/active_record_querying.textile20
1 files changed, 10 insertions, 10 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 38919b6d1f..1c5f5ada4a 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -970,14 +970,14 @@ h4. Working with scopes
Where a relational object is required, the +scoped+ method may come in handy. This will return an +ActiveRecord::Relation+ object which can have further scoping applied to it afterwards. A place where this may come in handy is on associations
<ruby>
- client = Client.find_by_first_name("Ryan")
- orders = client.orders.scoped
+client = Client.find_by_first_name("Ryan")
+orders = client.orders.scoped
</ruby>
With this new +orders+ object, we are able to ascertain that this object can have more scopes applied to it. For instance, if we wanted to return orders only in the last 30 days at a later point.
<ruby>
- orders.where("created_at > ?", 30.days.ago)
+orders.where("created_at > ?", 30.days.ago)
</ruby>
h4. Applying a default scope
@@ -985,23 +985,23 @@ h4. Applying a default scope
If we wish for a scope to be applied across all queries to the model we can use the +default_scope+ method within the model itself.
<ruby>
- class Client < ActiveRecord::Base
- default_scope where("removed_at IS NULL")
- end
+class Client < ActiveRecord::Base
+ default_scope where("removed_at IS NULL")
+end
</ruby>
When queries are executed on this model, the SQL query will now look something like this:
-<ruby>
- SELECT * FROM clients WHERE removed_at IS NULL
-</ruby>
+<sql>
+SELECT * FROM clients WHERE removed_at IS NULL
+</sql>
h4. Removing all scoping
If we wish to remove scoping for any reason we can use the +unscoped+ method. This is especially useful if a +default_scope+ is specified in the model and should not be applied for this particular query.
<ruby>
- Client.unscoped.all
+Client.unscoped.all
</ruby>
This method removes all scoping and will do a normal query on the table.