Topic: Find First Sorting

Hi,

I'm trying to sort the info found by (:first)...is that possible? 

#Model
Person
  has_many :dogs

Dog
  belongs_to :person


#Controller
@person = Person.find_by_id(4)
@coolest_dog = @person.dogs.find(:first, order => "coolness DESC")

#Dog Table
id/person_id/coolness
1/4/1
2/4/2
3/4/3


I always get the dog with id 1 and I want to get id 3.  What am I screwing up?

Thanks,
/db

Re: Find First Sorting

Yep, should be possible, but it looks like you forgot the colon to make "order" a symbol:

@coolest_dog = @person.dogs.find(:first, :order => "coolness DESC")

I'm surprised this didn't report an error.

Railscasts - Free Ruby on Rails Screencasts

Re: Find First Sorting

Stupid typos - I just typed that in since I am substituting model names to make the code more readable.  If it should work then I must have something else messed up.  I'll verify and get back if I run into problems.  Thanks as always,

/db

Re: Find First Sorting

If it still isn't working, check out the development.log file to see the query that is getting sent to the database. Post it here if you need help understanding it.

Railscasts - Free Ruby on Rails Screencasts