Difference between count, length and size in an association with ActiveRecord
21-Apr-2022 1392
With Rails/ActiveRecord, you can count the records in an association using three methods .count, .length, .size.As a rails newbie, when you first discover this, it can be confusing… Why do we need three methods? Is there any advantage to using one method over the other? How are they different?Here are 6 characteristics of this three methods that you should know. They will help you decide which method to use on different situations.I will also share a why I think that most of the time you should start with .size and the reference to the docs where you can find more information.
Difference between count, length and size in an association with ActiveRecord #ruby #rubydeveloper #rubyonrails #Difference #between #count, #length #association #ActiveRecord #activerecord https://rubyonrails.ba/link/difference-between-count-length-and-size-in-an-association-with-activerecord