diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-10-08 14:21:09 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-10-08 14:21:09 -0300 |
commit | 2f5ceffdfa10037dccb58c5faafd26af27de63aa (patch) | |
tree | 0164b5c3eced1d17cd9641042a7723f9ada6f734 | |
parent | a7bd1c7c886686934333cd60b18e6661bdd1cffa (diff) | |
parent | e2a4224352fa326c045c668850279f5b25e11530 (diff) | |
download | rails-2f5ceffdfa10037dccb58c5faafd26af27de63aa.tar.gz rails-2f5ceffdfa10037dccb58c5faafd26af27de63aa.tar.bz2 rails-2f5ceffdfa10037dccb58c5faafd26af27de63aa.zip |
Merge pull request #21911 from tommyblue/master
Modify the scope method documentation
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 7b62626896..b2f25752d3 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -39,8 +39,12 @@ module ActiveRecord end end - # Adds a class method for retrieving and querying objects. A \scope - # represents a narrowing of a database query, such as + # Adds a class method for retrieving and querying objects. + # The method is intended to return an <tt>ActiveRecord::Relation</tt> + # object, which is composable with other scopes. + # If it returns +nil+ or +false+, an <tt>all</tt> scope is returned instead. + # + # A \scope represents a narrowing of a database query, such as # <tt>where(color: :red).select('shirts.*').includes(:washing_instructions)</tt>. # # class Shirt < ActiveRecord::Base @@ -66,7 +70,8 @@ module ActiveRecord # end # # Unlike <tt>Shirt.find(...)</tt>, however, the object returned by - # <tt>Shirt.red</tt> is not an Array; it resembles the association object + # <tt>Shirt.red</tt> is not an Array but an <tt>ActiveRecord::Relation</tt>, + # which is composable with other scopes; it resembles the association object # constructed by a +has_many+ declaration. For instance, you can invoke # <tt>Shirt.red.first</tt>, <tt>Shirt.red.count</tt>, # <tt>Shirt.red.where(size: 'small')</tt>. Also, just as with the |