I wish to make a move a little like -

@apples  = Fruit.find :all, :conditions => ["type = ?", "apple"]
@pears   = Fruit.find :all, :conditions => ["type = ?", "pear"]
@tomatos = Fruit.find :all, :conditions => ["type = ?", "tomato"]

The issue is this takes 3 DB demands. It is possible to method to mix these therefore it only makes 1 request but will get all of the needed info?

Thanks, Alex

I believe you may want to get all fruits whose type might be "apple" or "pear" or "tomato" after which in ruby iterate to produce the needed assortment of Fruits.

   @fruits = Fruit.find :all, :conditions => ["type = ? or type =? or type =? , "apple", "pear", "tomata"]

Then in ruby that you can do something similar to this (very fundamental).

 @apples = @fruits.select{|f| f.type == "apple"}

Like stated already within the comment, managing a large query and fetching all records after which choosing them via Ruby could be a discomfort within the ass. There a couple of good reasons to let MySQL (or whatever database you're using) get the job done:

  1. For those who have a million records, Ruby need to instantiate a million ActiveRecord objects. This utilizes memory extremely fast, and may build your application useless, particularly in production. Imagine 100 customers being able to access your website, and every of the dynos (hopefully you've several) needs to load a million records and compare a million strings!

  2. Allow the database do their jobs. That like their jobs, and they're great in internet marketing. Actually they're enhanced to operate such queries. In case your database appears to become slow, look at your indices and tweak them if required.

  3. It can make your code ugly and even perhaps unreadable getting a large query after which splitting up, rather than 3 variables, each defined and fetched in it's own row.