# Extra SQL calls invoked using paginate

**URL:** <https://www.ruby-forum.com/t/extra-sql-calls-invoked-using-paginate/122153>\
**Category:** Rails\
**Created:** [December 5, 2007, 12:25am UTC](https://www.ruby-forum.com/t/extra-sql-calls-invoked-using-paginate/122153 "2007-12-05T00:25:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcarlson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mcarlson](https://www.ruby-forum.com/u/mcarlson)\
**Post date:** [December 5, 2007, 12:25am UTC](https://www.ruby-forum.com/t/extra-sql-calls-invoked-using-paginate/122153/1 "2007-12-05T00:25:09Z")

</div>

I am using the paginate helper method to retrieve data from 2 tables.  
Here is a sample of what the call looks like:

@paginator, @entries = paginate(:model\_name, :include =\>  
‘another\_model\_name’, :conditions =\> conditions, :per\_page =\>  
method\_returns\_number(), :order =\> @var\_with\_sort\_params)

the problem I am having is there are extra SQL calls made after the  
data is retrieved in the log… basically, paginate goes off and does  
its thing running the queries required for the data, and then last but  
not least, it makes a call like this for every record I have in my  
page (so 10 records per page - 10 of these calls) to the ‘:include’  
table

2007-12-04 PST 14:59:48 DEBUG: [4;35;1mSQL (0.004367) [0m  
[0mSELECT \* FROM another\_model\_table WHERE (another\_model\_table.[id]  
= 643) [0m

\*Obviously I have changed the table names and sensitive information,  
but in essence this is my issue…

Why am I getting all these extra calls per row in my page, I don’t see  
this in similar use of the paginate helper in the application. Has  
anyone else run into this?

I have tried several ways to debug, but I am open to suggestions there  
too if you don’t have a solution.

Thanks.

---

<div class="post-metadata">

**Author:** ![mcarlson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mcarlson](https://www.ruby-forum.com/u/mcarlson)\
**Post date:** [December 5, 2007, 1:13am UTC](https://www.ruby-forum.com/t/extra-sql-calls-invoked-using-paginate/122153/2 "2007-12-05T01:13:29Z")

</div>

Matthew C. wrote:

> not least, it makes a call like this for every record I have in my  
> page (so 10 records per page - 10 of these calls) to the ‘:include’  
> table
> 
> 2007-12-04 PST 14:59:48 DEBUG: [4;35;1mSQL (0.004367) [0m  
> [0mSELECT \* FROM another\_model\_table WHERE (another\_model\_table.[id]  
> = 643) [0m  
> […]

Are you sure this is the call to paginate that creates these queries and  
not another part of your code (maybe in the view for example)?

Lionel
