diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-17 22:43:51 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-17 22:43:51 -0500 |
commit | 3c91c8127050c7abbe091c19052f9813a62b1af7 (patch) | |
tree | ca5dd84dc4b4a367645840a318bbbcd97b045beb /activerecord/lib | |
parent | 2e2d3814497baacd2c6d0764f8430943cc1d4a7c (diff) | |
download | rails-3c91c8127050c7abbe091c19052f9813a62b1af7.tar.gz rails-3c91c8127050c7abbe091c19052f9813a62b1af7.tar.bz2 rails-3c91c8127050c7abbe091c19052f9813a62b1af7.zip |
add docs to CollectionAssociation#many?
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 19ca63d8b8..3e29edfe64 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -282,7 +282,40 @@ module ActiveRecord end end - # Returns true if the collection has more than 1 record. Equivalent to collection.size > 1. + # Returns true if the collection has more than 1 record. + # Equivalent to +collection.size > 1+. + # + # class Person < ActiveRecord::Base + # has_many :pets + # end + # + # person.pets.count #=> 1 + # person.pets.many? #=> false + # + # person.pets << Pet.new(name: 'Snoopy') + # person.pets.count #=> 2 + # person.pets.many? #=> true + # + # Also, you can pass a block to define a criteria. The + # behaviour is the same, it returns true if the collection + # based on the criteria has more than 1 record. + # + # person.pets + # # => [ + # # #<Pet name: "GorbyPuff", group: "cats">, + # # #<Pet name: "Wy", group: "cats">, + # # #<Pet name: "Snoop", group: "dogs"> + # # ] + # + # person.pets.many? do |pet| + # pet.group == 'dogs' + # end + # # => false + # + # person.pets.many? do |pet| + # pet.group == 'cats' + # end + # # => true def many? if block_given? load_target.many? { |*block_args| yield(*block_args) } |