instance method
empty?
Ruby on Rails 4.2.9
Since v4.0.13Signature
empty?()
Returns true if the collection is empty. If the collection has been loaded it is equivalent to collection.size.zero?. If the collection has not been loaded, it is equivalent to collection.exists?. If the collection has not already been loaded and you are going to fetch the records anyway it is better to check collection.length.zero?.
class Person < ActiveRecord::Base has_many :pets end person.pets.count # => 1 person.pets.empty? # => false person.pets.delete_all person.pets.count # => 0 person.pets.empty? # => true
Source
# File activerecord/lib/active_record/associations/collection_proxy.rb, line 772
def empty?
@association.empty?
end
Defined in activerecord/lib/active_record/associations/collection_proxy.rb line 772
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Associations::CollectionProxy