Forum: Ruby on Rails Paginate Not Including Other Tables w/ :include?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 lists (Guest)
on 2005-12-05 00:33
(Received via mailing list)
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
F7975423060c2c9e4395dca3ae870771?d=identicon&s=25 De Railed (kitesurfer)
on 2005-12-05 02:33
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...
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 lists (Guest)
on 2005-12-05 02:50
(Received via mailing list)
class MerchItem < ActiveRecord::Base
    has_many :merch_formats, :dependent => true
end

class MerchFormat < ActiveRecord::Base
    belongs_to :merch_item
end
754e1c849101a2b96e441e7b897abc37?d=identicon&s=25 Jeremy Hopple (Guest)
on 2005-12-12 19:16
(Received via mailing list)
I just created a new rails plugin (
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
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 Hunter's Lists (Guest)
on 2005-12-12 19:52
(Received via mailing list)
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 Hopple <jeremy@jthopple.com>
Reply-To: <rails@lists.rubyonrails.org>
Date: Mon, 12 Dec 2005 13:15:01 -0500
To: <rails@lists.rubyonrails.org>
Subject: Re: [Rails] Paginate Not Including Other Tables w/ :include?

I just created a new rails plugin
(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
This topic is locked and can not be replied to.