Browse files

minor indentation fixes on a6293ff

  • Loading branch information...
1 parent 5f5feb2 commit 798aa881af53075ed6bbc73d19556b001af68ab7 @vijaydev vijaydev committed Jun 26, 2011
Showing with 10 additions and 10 deletions.
  1. +10 −10 railties/guides/source/active_record_querying.textile
@@ -970,38 +970,38 @@ 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
- client = Client.find_by_first_name("Ryan")
- orders = client.orders.scoped
+client = Client.find_by_first_name("Ryan")
+orders = client.orders.scoped
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.
- orders.where("created_at > ?", 30.days.ago)
+orders.where("created_at > ?", 30.days.ago)
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.
- class Client < ActiveRecord::Base
- default_scope where("removed_at IS NULL")
- end
+class Client < ActiveRecord::Base
+ default_scope where("removed_at IS NULL")
When queries are executed on this model, the SQL query will now look something like this:
- SELECT * FROM clients WHERE removed_at IS NULL
+SELECT * FROM clients WHERE removed_at IS NULL
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.
- Client.unscoped.all
This method removes all scoping and will do a normal query on the table.

0 comments on commit 798aa88

Please sign in to comment.