views:

74

answers:

2

Quick one, but thought I'd ask.

Is there a better way of getting the column values from a model's column than something like this?

Item.count(:all, :group => 'status').reject! { |i, e| i.blank? }.collect { |i,e| i}
A: 

Is it the same thing as the following code?

Item.count(:all, :group => "status", :conditions => "status != ''"}

.. maybe not ..

but then could you please specify more criteria you want? i.e. status is blank? count is blank?

Sikachu
+1  A: 
Item.find(:all, :select=>:status, :group => 'status', :conditions => "status != ''").collect{|r| r.status}
aivarsak
thanks. wasn't aware of the select hash-key on find.
The Pied Pipes
There is a finders guide: http://guides.rubyonrails.org/finders.html
Ryan Bigg