# Pagination with eagerfindersql

**URL:** <https://www.ruby-forum.com/t/pagination-with-eagerfindersql/122660>\
**Category:** Rails\
**Created:** [December 10, 2007, 2:19pm UTC](https://www.ruby-forum.com/t/pagination-with-eagerfindersql/122660 "2007-12-10T14:19:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [December 10, 2007, 2:19pm UTC](https://www.ruby-forum.com/t/pagination-with-eagerfindersql/122660/1 "2007-12-10T14:19:25Z")

</div>

I have installed the plugin eagerfindersql.

if i try to insert :limit and offset in find:  
events=Event.find(:all, :limit=\>10,:offset =\> 0,:include =\>  
[:event\_type\_names,{:event\_dates =\> {:place =\> :locality}}],  
:finder\_sql =\> query,  
:column\_mapping =\> {…

this not works and show all elements.

if i try to insert limit in query. the events that returning are less of  
10.

Beacuse all events have more event\_dates.

How i can to use limit???

Thanks

---

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [December 10, 2007, 2:46pm UTC](https://www.ruby-forum.com/t/pagination-with-eagerfindersql/122660/2 "2007-12-10T14:46:18Z")

</div>

On 10 Dec 2007, at 13:19, Luca R. wrote:

> this not works and show all elements.
> 
> if i try to insert limit in query. the events that returning are  
> less of  
> 10.

With the plugin, the sql that is used is the one passed via  
the :finder\_sql.  
Just looking quickly at the plugin’s code, this suggests that it will  
ignore the :limit and :offset you’re supplying.  
You just have to write the whole query yourself (which is rather the  
point of the plugin)

Fred

---

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [December 10, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/pagination-with-eagerfindersql/122660/3 "2007-12-10T15:42:01Z")

</div>

Frederick C. wrote:

> On 10 Dec 2007, at 13:19, Luca R. wrote:
> 
> > this not works and show all elements.
> > 
> > if i try to insert limit in query. the events that returning are  
> > less of  
> > 10.
> 
> With the plugin, the sql that is used is the one passed via  
> the :finder\_sql.  
> Just looking quickly at the plugin’s code, this suggests that it will  
> ignore the :limit and :offset you’re supplying.  
> You just have to write the whole query yourself (which is rather the  
> point of the plugin)
> 
> Fred

But if i insert limit in the finder\_sql the number of the elements  
selected are less of limit setted.

---

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [December 10, 2007, 4:34pm UTC](https://www.ruby-forum.com/t/pagination-with-eagerfindersql/122660/4 "2007-12-10T16:34:51Z")

</div>

On 10 Dec 2007, at 14:42, Luca R. wrote:

> > With the plugin, the sql that is used is the one passed via  
> > the :finder\_sql.  
> > Just looking quickly at the plugin’s code, this suggests that it will  
> > ignore the :limit and :offset you’re supplying.  
> > You just have to write the whole query yourself (which is rather the  
> > point of the plugin)
> > 
> > Fred
> 
> But if i insert limit in the finder\_sql the number of the elements  
> selected are less of limit setted.

You’re probably running into the fact that limiting and eager loading  
don’t really mix. You’ll probably have to replicate what activerecord  
does under the hood when you don’t use eagerfindersql:  
1 query to determine which events to load (and get back from that the  
ids to load), and a second query that loads them with the associations.

Fred
