Topic: will_paginate and NoMethodError on :order while eager loading

Hi;

I've been combining a will_paginate object with eager loading, and I'm getting an error when I include an :order parameter.

a Song has_many :placements, :placements is a join model, and :title is a column in Songs.

 @songs = Song.paginate :page => params[:page], :include => :placements, :per_page => 4, :order => :title

results in

NoMethodError (private method `scan' called for :title:Symbol):

It works if I omit :order => :title like

@songs = Song.paginate :page => params[:page], :include => :placements, :per_page => 4

Am I doing something drastically wrong here?

Re: will_paginate and NoMethodError on :order while eager loading

:order value should be a string:
:order => "title"

Re: will_paginate and NoMethodError on :order while eager loading

Great! That did it. Thanks Dup.

If I :include => {:placements => :spot} an associated model that also has a 'title' column, I get an ambiguous SQL command. Is there some way to distinguish which 'title' you want :order to act upon?

Re: will_paginate and NoMethodError on :order while eager loading

:order => "songs.title"

note that the string you pass to :order is an SQL string, so you don't use the names of the models or associations, but the actual table name. So here i assume, that you follow the Rails convention and therefore, the table of the Song model is named "songs"

Re: will_paginate and NoMethodError on :order while eager loading

Ah I get it.

Thanks again.