Topic: count rows in a table efficiently?

I need to find out how many rows (entries) one of my tables has.

The best I've been able to find is

count = MyModel.find_by_sql("SELECT COUNT(*) FROM MyModels");

I get back a one element array, with the element being an instance of MyModel, except it only has one attribute { "COUNT(*)" => 8 }

This doesn't seem right, but it also doesn't seem wrong in that it seems like it's pretty efficient and tasking the database minimally.

Re: count rows in a table efficiently?

Try

MyModel.count

Ruby Rockstars - Ruby Jobs for all!