Method: ActiveRecord::Associations::CollectionAssociation#length

Defined in:
activerecord/lib/active_record/associations/collection_association.rb

#lengthObject

Returns the size of the collection calling size on the target.

If the collection has been already loaded length and size are equivalent. If not and you are going to need the records anyway this method will take one less query. Otherwise size is more efficient.



287
288
289
# File 'activerecord/lib/active_record/associations/collection_association.rb', line 287

def length
  load_target.size
end