DEV Community

Daniel Todd
Daniel Todd

Posted on

benefits on the method .count

Hello all,

I have been working on 'ActiveRecord' as of lately, and I was wondering if one could explain the benefits of running:

restaurant.all.length # slower at is runs all data from the table

as compared to:

restaurant.count # finds the unique ID

I understand that this will ultimately speed up the process, but when would it be better to allow for the run of all the data in every table as compared to the unique ID in the .count method?

Is there a specific time one should run one over the other?

Top comments (0)