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
KiteSurfer KiteSurfer
2005-Dec-05 01:33 UTC
Re: Paginate Not Including Other Tables w/ :include?
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... -- Posted via http://www.ruby-forum.com/.
Hunter Hillegas
2005-Dec-05 01:46 UTC
Re: Re: Paginate Not Including Other Tables w/ :include?
class MerchItem < ActiveRecord::Base has_many :merch_formats, :dependent => true end class MerchFormat < ActiveRecord::Base belongs_to :merch_item end> From: KiteSurfer KiteSurfer <fernand-YPVloBjEdNw@public.gmane.org> > Reply-To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Date: Mon, 5 Dec 2005 02:33:26 +0100 > To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Subject: [Rails] Re: Paginate Not Including Other Tables w/ :include? > > 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... > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
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 On 12/4/05, Hunter Hillegas <lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org> wrote:> > 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 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hunter''s Lists
2005-Dec-12 18:51 UTC
Re: Paginate Not Including Other Tables w/ :include?
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-XPxzCiB2I4RWk0Htik3J/w@public.gmane.org> Reply-To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> Date: Mon, 12 Dec 2005 13:15:01 -0500 To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.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 On 12/4/05, Hunter Hillegas <lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org> wrote:> 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 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails