diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2010-12-23 14:55:42 +1000 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2010-12-23 14:55:42 +1000 |
commit | b4b2574a12f7a3b6db97d28eda894ad872445190 (patch) | |
tree | fac889110c42c9dd01b3ede8ca0e78467b439356 | |
parent | f411451ed513d982a2a14e62c38f030a3560ea42 (diff) | |
download | rails-b4b2574a12f7a3b6db97d28eda894ad872445190.tar.gz rails-b4b2574a12f7a3b6db97d28eda894ad872445190.tar.bz2 rails-b4b2574a12f7a3b6db97d28eda894ad872445190.zip |
Query guide: fix indentation
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 6c1042e70e..5cd302f356 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/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 |