Permalink
Browse files

Query guide: fix indentation

  • Loading branch information...
1 parent f411451 commit b4b2574a12f7a3b6db97d28eda894ad872445190 @radar radar committed Dec 23, 2010
Showing with 13 additions and 13 deletions.
  1. +13 −13 railties/guides/source/active_record_querying.textile
@@ -728,39 +728,39 @@ Scoping allows you to specify commonly-used ARel queries which can be referenced
To define a simple scope, we use the +scope+ method inside the class, passing the ARel query that we'd like run when this scope is called:
<ruby>
- class Post < ActiveRecord::Base
- scope :published, where(:published => true)
- end
+class Post < ActiveRecord::Base
+ scope :published, where(:published => true)
+end
</ruby>
Just like before, these methods are also chainable:
<ruby>
- class Post < ActiveRecord::Base
- scope :published, where(:published => true).joins(:category)
- end
+class Post < ActiveRecord::Base
+ scope :published, where(:published => true).joins(:category)
+end
</ruby>
Scopes are also chainable within scopes:
<ruby>
- class Post < ActiveRecord::Base
- scope :published, where(:published => true)
- scope :published_and_commented, published.and(self.arel_table[:comments_count].gt(0))
- end
+class Post < ActiveRecord::Base
+ scope :published, where(:published => true)
+ scope :published_and_commented, published.and(self.arel_table[:comments_count].gt(0))
+end
</ruby>
To call this +published+ scope we can call it on either the class:
<ruby>
- Post.published => [published posts]
+Post.published => [published posts]
</ruby>
Or on an association consisting of +Post+ objects:
<ruby>
- category = Category.first
- category.posts.published => [published posts belonging to this category]
+category = Category.first
+category.posts.published => [published posts belonging to this category]
</ruby>
h4. Working with times

0 comments on commit b4b2574

Please sign in to comment.