Explain what's different between ActiveRecord::Relation's count, length and size methods?

Submitted by: Muhammad
☛ count – counts the number of elements using query with the SQL command ‘COUNT' but the result is not stored internally during object life cycle. This means, each time we invoke this method, SQL query is performed again. You should use this method if you don't have anything loaded.
☛ length – loads all objects just to count them and then return the result count. It should be used only if you have already loaded all entries to avoid another database query.
☛ size – returns the size of the collection. If a collection is loaded, it will count its elements without any database query; but if a collection is not loaded, it will perform an additional query.
So we can say that size adapts to the situation.
Submitted by: Muhammad

Read Online Ruby on Rails Developer Job Interview Questions And Answers