On 27 August 2010 16:31, Marnen Laibow-Koser <[email protected]> wrote:
> Colin Law wrote:
>> On 27 August 2010 15:19, Dakshata Gulkhobare <[email protected]>
>> wrote:
>>> car_price = UsedCar.find(:all, :order => 'price DESC' )
>>
>> That will give you them all in descending price order so the first one
>> will be the most expensive.  You could have called it cars rather than
>> car_price to indicate that it is an array (or similar) of Cars.  If
>> you want them in price increasing you can say
>>
>> cars = UsedCar.find(:all, :order => :price)
>> or to get just the cheapest
>> cheapest_car = UsedCar.find(:all, :order => :price).first
>
> That will still retrieve all the records.  You want find :first, not
> find :all.

Yes of course, my mistake.  Though in fact rails could be clever
enough to work out from the statement find(:all).first that it only
needs to fetch the first one.  There is a limit to the magic it can
sensibly perform however, and I was trying to push it beyond that
limit.

Colin

-- 
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.

Reply via email to