Search code examples
ruby-on-railsrubyrubygemsruby-on-rails-plugins

How can i order the eager loaded model in rails


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.


Solution

  • you can do it in your model

    has_many :qualifications, :order => "start_date DESC"