# Paginate Not Including Other Tables w/ :include?

**URL:** <https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467>\
**Category:** Rails\
**Created:** [December 5, 2005, 12:33am UTC](https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467 "2005-12-05T00:33:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [December 5, 2005, 12:33am UTC](https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467/1 "2005-12-05T00:33:25Z")

</div>

I am trying to use pagniate as follows:

@merch\_pages, @merch = paginate :merch\_item, :per\_page =\> 15, :include  
=\>  
:merch\_formats, :conditions =\> [“active\_status = 1 AND format\_name = ?”,  
params[:id]]

My ‘merch\_item’ model contains a ‘has\_many :merch\_formats’.

active\_status and format\_name are defined on merch\_format, not  
merch\_item.

The problem is that the SQL generated isn’t including merch\_formats, it  
is  
simply outputting:

SELECT COUNT(\*) FROM merch\_items WHERE (active\_status = 1 AND  
format\_name =  
‘Sweatshirt’)

This of course fails, as the required JOIN wasn’t inserted.

Based on the paginate documentation, it seems that :include should work  
the  
same way that it does during a normal find.

What am I doing wrong?

Thanks,  
Hunter

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [December 5, 2005, 2:33am UTC](https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467/2 "2005-12-05T02:33:26Z")

</div>

What does the relationship from :merch\_item and merch\_formats look like  
?

I have a similar problem last week but my models objects were not  
properly configured…

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [December 5, 2005, 2:50am UTC](https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467/3 "2005-12-05T02:50:07Z")

</div>

class MerchItem \< ActiveRecord::Base  
has\_many :merch\_formats, :dependent =\> true  
end

class MerchFormat \< ActiveRecord::Base  
belongs\_to :merch\_item  
end

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [December 12, 2005, 7:16pm UTC](https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467/4 "2005-12-12T19:16:10Z")

</div>

I just created a new rails plugin (  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/Plugins#countlimit)) that makes  
:include work with paginate. This was enabled by changing Model.count  
so  
that it now accepts a hash of options including: :include and  
:conditions.  
This new Model.count is backwards compatible with the existing  
Model.countin ActiveRecord, and it passes all Active Record unit tests  
using MySQL and  
Postgres.

Check it out if you want to use eager loading with paginate… and  
please  
send any feedback my way!

You can get the plugin from:

svn://jthopple.com/public/rails/plugins/count\_limit\_associations

Thanks,  
Jeremy

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [December 12, 2005, 7:52pm UTC](https://www.ruby-forum.com/t/paginate-not-including-other-tables-w-include/49467/5 "2005-12-12T19:52:17Z")

</div>

ShouldnÂ¹t something like this be in the core?

It seems almost like a bug with Model.count if it canÂ¹t support all the  
options that the items that use it need…?

From: Jeremy H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Reply-To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Mon, 12 Dec 2005 13:15:01 -0500  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: [Rails] Paginate Not Including Other Tables w/ :include?

I just created a new rails plugin  
([Peak Obsession](http://wiki.rubyonrails.com/rails/pages/Plugins#countlimit)) that makes  
:include work with paginate. This was enabled by changing Model.count  
so  
that it now accepts a hash of options including: :include and  
:conditions.  
This new Model.count is backwards compatible with the existing  
Model.count  
in ActiveRecord, and it passes all Active Record unit tests using MySQL  
and  
Postgres.

Check it out if you want to use eager loading with paginate… and  
please  
send any feedback my way!

You can get the plugin from:

svn://jthopple.com/public/rails/plugins/count\_limit\_associations

Thanks,  
Jeremy
