Forum: Ruby on Rails Rails pagination problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
74a56286718bc003d6c7438f7efa1e3a?d=identicon&s=25 Navjeet Chabbewal (jeet)
on 2006-02-01 19:08
I am having this problem with pagination query in my controller class.
I am using SQL server and following code to create pagination fails,
complains about column name 'program_name' (which is valid
column/attribute of program)

The error message is:

DBI::DatabaseError: S0022 (207) [Microsoft][ODBC SQL Server
Driver][SQL Server]Invalid column name 'program_name'.: SELECT * FROM
(SELECT TOP 3 * FROM (......rest of query deleted......


query_term = '%tiger%'
@program_pages, @programs = paginate :programs, :conditions =>
["program_name like ?", query_term], :per_page => 5, :include =>
[:status], :order => 'program_name'


If I remove ":include => [:status]" from the paginate crestion code,
it works fine. So the following works:

@program_pages, @programs = paginate :programs, :conditions =>
["program_name like ?", query_term], :per_page => 5, :order =>
'program_name'


I have to include status Active Record class because :order clause is
dynamic and may be by status name which in status model (program model
belongs_to status)

The :include works fine on Program.find(...) in console as below:

>> p = Program.find(:all, :include => [:status], :order =>
'program_name' ).each { |prog| puts prog.status_code,
prog.status.Status}

Is this a sql server issue or I am not doing something correctly.



--Jeet
Aae0fc3fa21923967f479385a6cd8c4a?d=identicon&s=25 Steven Spriggs (zaroh)
on 2009-06-04 20:19
Navjeet,

Did you ever find a solution to this problem?

I have encountered the same issue and was wondering what steps you took
to solve it if any.

Thanks,

Steve


Navjeet Chabbewal wrote:
> I am having this problem with pagination query in my controller class.
> I am using SQL server and following code to create pagination fails,
> complains about column name 'program_name' (which is valid
> column/attribute of program)
>
> The error message is:
>
> DBI::DatabaseError: S0022 (207) [Microsoft][ODBC SQL Server
> Driver][SQL Server]Invalid column name 'program_name'.: SELECT * FROM
> (SELECT TOP 3 * FROM (......rest of query deleted......
>
>
> query_term = '%tiger%'
> @program_pages, @programs = paginate :programs, :conditions =>
> ["program_name like ?", query_term], :per_page => 5, :include =>
> [:status], :order => 'program_name'
>
>
> If I remove ":include => [:status]" from the paginate crestion code,
> it works fine. So the following works:
>
> @program_pages, @programs = paginate :programs, :conditions =>
> ["program_name like ?", query_term], :per_page => 5, :order =>
> 'program_name'
>
>
> I have to include status Active Record class because :order clause is
> dynamic and may be by status name which in status model (program model
> belongs_to status)
>
> The :include works fine on Program.find(...) in console as below:
>
>>> p = Program.find(:all, :include => [:status], :order =>
> 'program_name' ).each { |prog| puts prog.status_code,
> prog.status.Status}
>
> Is this a sql server issue or I am not doing something correctly.
>
>
>
> --Jeet
This topic is locked and can not be replied to.