On Jul 13, 2:41 am, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> Conrad Taylor wrote:
>
> [...]
>
> > I agree with Fred's approach because if you're testing for emptiness,
> > you
> > should do the least amount of work to determine it.
>
> Excellent point.
>
> > For example,
>
> > Model.first => will create 1 or no objects
> > Model.all => will create table size of N or no objects
>
> Better still:
>
> Model.count => will create one Numeric and that's all!
In ruby land yes, this is cheaper but not for the database: with
Model.first the database gets just one row and then stops, with
Model.count it has to count the whole table (which can be expensive on
a large table - usually the db will scan an appropriate index)
Fred
>
> > Good luck,
>
> > -Conrad
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> [email protected]
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---