# Will\_paginate with more than one table

**URL:** <https://www.ruby-forum.com/t/will-paginate-with-more-than-one-table/172159>\
**Category:** Rails\
**Created:** [July 15, 2009, 7:59pm UTC](https://www.ruby-forum.com/t/will-paginate-with-more-than-one-table/172159 "2009-07-15T19:59:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 15, 2009, 7:59pm UTC](https://www.ruby-forum.com/t/will-paginate-with-more-than-one-table/172159/1 "2009-07-15T19:59:42Z")

</div>

Hi you all, I have an app where I do two “finds” in different tables:

@results\_m = Man.find(:all)  
@results\_w = Woman.find(:all)

I can paginate each of one with paginate:  
@results\_m = Man.paginate([params page stuff here…])  
@results\_w = Woman.paginate([params page stuff here…])

However, I want to show the two kinds of results in the same view and  
with the pagination as if they were only from a single type of resource.  
Can will\_paginate do the trick somehow? (maybe something like @results =  
@results\_m + @results\_w, which of course also sums the total records in  
Man table and Woman table). Or should I do it manually?

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 16, 2009, 6:47am UTC](https://www.ruby-forum.com/t/will-paginate-with-more-than-one-table/172159/2 "2009-07-16T06:47:58Z")

</div>

> ## However, I want to show the two kinds of results in the same view and with the pagination as if they were only from a single type of resource. Can will\_paginate do the trick somehow? (maybe something like @results = @results\_m + @results\_w, which of course also sums the total records in Man table and Woman table). Or should I do it manually?
> 
> Posted viahttp://www.ruby-forum.com/.

Are you looking for single table inheritance?

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 16, 2009, 11:57am UTC](https://www.ruby-forum.com/t/will-paginate-with-more-than-one-table/172159/3 "2009-07-16T11:57:20Z")

</div>

Ummm… not exactly. I have an app consisting on database federation,  
so basically I have to get the results of one table, get the results of  
other one, and merge them.  
The problem is that if I paginate the first result I get, let’s say, 10  
records, then I paginate the second and I get 10 records, so the  
resulting one is 20 records size, not 10. I can paginate also this last  
one set of 20 results, but I would lost the total\_pages of the original  
two first results. Apart from that, the gem should manage which table  
and with which limit and offset to ask when I do a request such as  
http://…/whatever?page=x

So I’m afraid I shall do it manually somehow. Don’t think any paginating  
gem/plugin have a solution to this.

pharrington wrote:

> > ## However, I want to show the two kinds of results in the same view and with the pagination as if they were only from a single type of resource. Can will\_paginate do the trick somehow? (maybe something like @results = @results\_m + @results\_w, which of course also sums the total records in Man table and Woman table). Or should I do it manually?
> > 
> > Posted viahttp://www.ruby-forum.com/.
> 
> Are you looking for single table inheritance?
