This method is deprecated or moved on the latest stable version.
The last existing version (v5.0.0.1) is shown here.
count(column_name = nil)
public
Count all records using SQL. Construct options and pass them with scope
to the target class’s count.
# File activerecord/lib/active_record/associations/collection_association.rb, line 251
def count(column_name = nil)
relation = scope
if association_scope.distinct_value
# This is needed because 'SELECT count(DISTINCT *)..' is not valid SQL.
column_name ||= reflection.klass.primary_key
relation = relation.distinct
end
value = relation.count(column_name)
limit = options[:limit]
offset = options[:offset]
if limit || offset
[ [value - offset.to_i, 0].max, limit.to_i ].min
else
value
end
end