Forum: Ruby on Rails Dynamic finders vs. standard find(:all) with condition

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andrew H. (Guest)
on 2007-02-26 22:46
Is there a difference between the way collections are returned using a
dynamic finder and a standard find all with a condition?

I decided to convert this...

@reservations = Reservation.find(:all, :conditions => ["status = ?",
"Pending"])

...to this...

@reservations = Reservation.find_by_status("Pending")

...because it's much more readable and I prefer dynamic finders over
conditions whenever possible.  However, the collection returned by the
dynamic finder apparently doesn't have the "empty?" method available to
it.  I use @reservations.empty? in my view to evaluate if I have an
empty collection of objects and react accordingly.

Is there something I'm missing?  Do dynamic finders return objects in a
different manner than regular finds?
Andrew H. (Guest)
on 2007-02-26 22:53
Bah I'm an idiot.  Disregard this.  I forgot to use find_all_by_status
instead of find_by_status.
This topic is locked and can not be replied to.