instance method
many?
Ruby on Rails 4.0.13
Since v4.0.13Signature
many?(&block)
Returns true if the collection has more than one 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
You can also pass a block to define criteria. The behavior is the same, it returns true if the collection based on the criteria has more than one record.
person.pets
# => [
# #<Pet name: "Gorby", group: "cats">,
# #<Pet name: "Puff", 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
Parameters
-
blockblock
Source
# File activerecord/lib/active_record/associations/collection_proxy.rb, line 818
def many?(&block)
@association.many?(&block)
end
Defined in activerecord/lib/active_record/associations/collection_proxy.rb line 818
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Associations::CollectionProxy