# Rails pagination problem

**URL:** <https://www.ruby-forum.com/t/rails-pagination-problem/53322>\
**Category:** Rails\
**Created:** [February 1, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/rails-pagination-problem/53322 "2006-02-01T19:08:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [February 1, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/rails-pagination-problem/53322/1 "2006-02-01T19:08:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [June 4, 2009, 8:19pm UTC](https://www.ruby-forum.com/t/rails-pagination-problem/53322/2 "2009-06-04T20:19:53Z")

</div>

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 C. 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
