views:

38

answers:

2

Hello All,

I shot a find query to include certain models in rails but i want to order the included models by my custom criterion. I have shot the query like the following to fetch the qualifications associated with the user ordering the qualifications by the start_date:

@user = User.find @current_user.id, :include => [:profile, {:qualifications=>{:order=>'start_date DESC'}}]

But when i run this in rails, it says that it can't find association named order. Any help is appreciated.

Thanks.

+1  A: 

you can do it in your model

has_many :qualifications, :order => "start_date DESC" 
roman
+1  A: 

If you want to order individually per find, do it this way:

@user = User.find @current_user.id, :include => [:profile, :qualifications], :order=>'qualifications.start_date DESC'

That means, move the table name into the order option.

hurikhan77