Damaris Fuentes
2008-Jan-18 15:08 UTC
Will_paginate and :conditions or :select with associations
Hi you all, I''m using Will_paginate plugin for paginating my results, and it worked fine with just one model, even adding the :select param, such as: select_statement = "DISTINCT " + @att @bugs = Bug.paginate(:page => params[:page], :per_page=>30, :select => select_statement, :order => @att) The problem is when I do something like: @client.bugs.paginate(:page => params[:page], :per_page=>30, :select => select_statement, :order => @att) It''s the same, but getting the bugs of one client. And this does not work. The things in "select", or in "conditions", are inexistent for will_paginate (i see in the log file the select clause does not contain anything of what is stated in "select" or "conditions" params. Any ideas? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sishen
2008-Jan-19 02:41 UTC
Re: Will_paginate and :conditions or :select with associations
paginate is a class method of ActiveRecord::Base, not class Array. That''s why @client.bugs failed, i think. You can use :join/:include to achieve your goal. On Jan 18, 2008 11:08 PM, Damaris Fuentes <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi you all, > I''m using Will_paginate plugin for paginating my results, and it worked > fine with just one model, even adding the :select param, such as: > > select_statement = "DISTINCT " + @att > @bugs = Bug.paginate(:page => params[:page], :per_page=>30, :select => > select_statement, :order => @att) > > The problem is when I do something like: > @client.bugs.paginate(:page => params[:page], :per_page=>30, :select => > select_statement, :order => @att) > > > It''s the same, but getting the bugs of one client. And this does not > work. > The things in "select", or in "conditions", are inexistent for > will_paginate (i see in the log file the select clause does not contain > anything of what is stated in "select" or "conditions" params. > > Any ideas? Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2008-Jan-19 15:23 UTC
Re: Will_paginate and :conditions or :select with associations
Sorry but, where do I have to use the join and include, in the paginate method? ( I suppose...:S) However, if so, the "will_paginate" plugin is very restrictive. I mean, IMHO, it''s very common to paginate results from associations. I will also look for another plugin to paginate. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sishen
2008-Jan-19 19:54 UTC
Re: Will_paginate and :conditions or :select with associations
On Jan 19, 2008 11:23 PM, Damaris Fuentes <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Sorry but, where do I have to use the join and include, in the paginate > method? ( I suppose...:S)yes. the similar usage like find. for example, Model.pagindate :include => [], :conditions =>[], :group => xx, :order => xx, :page => xx. Very simple, isn''t it? :) Hope it''s helpful.> > > However, if so, the "will_paginate" plugin is very restrictive. I mean, > IMHO, it''s very common to paginate results from associations. I will > also look for another plugin to paginate. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2008-Jan-20 17:06 UTC
Re: Will_paginate and :conditions or :select with associations
Um, but the "join" and "include" methods makes references to "belongs_to" associations and so, am I correct? The problem is my associations are not these ones, I mean, I don''t have the associations define with belongs_to and has_many and so. My models are: class Bug < ActiveRecord::Base def client Client.find_by_dirip(self.diripa) end end class Client < ActiveRecord::Base def bugs Bug.find_all_by_diripa(self.dirip) end end So... if I want to paginate the Bugs of one Client with certain conditions... how could I with will_paginate? :( Thanks. sishen wrote:> On Jan 19, 2008 11:23 PM, Damaris Fuentes > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> >> Sorry but, where do I have to use the join and include, in the paginate >> method? ( I suppose...:S) > > > yes. the similar usage like find. > > for example, > > Model.pagindate :include => [], :conditions =>[], :group => xx, :order > => > xx, :page => xx. > > Very simple, isn''t it? :) Hope it''s helpful.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sishen
2008-Jan-20 18:55 UTC
Re: Will_paginate and :conditions or :select with associations
On Jan 21, 2008 1:06 AM, Damaris Fuentes <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Um, but the "join" and "include" methods makes references to > "belongs_to" associations and so, am I correct? > > The problem is my associations are not these ones, I mean, I don''t have > the associations define with belongs_to and has_many and so. My models > are: > > class Bug < ActiveRecord::Base > def client > Client.find_by_dirip(self.diripa) > end > end > > class Client < ActiveRecord::Base > def bugs > Bug.find_all_by_diripa(self.dirip) > end > end > > So... if I want to paginate the Bugs of one Client with certain > conditions... how could I with will_paginate? :(Bug.paginate :include => [:client], :conditions => [''client_id = ?'', client.id]> > > Thanks. > > sishen wrote: > > On Jan 19, 2008 11:23 PM, Damaris Fuentes > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > >> > >> Sorry but, where do I have to use the join and include, in the paginate > >> method? ( I suppose...:S) > > > > > > yes. the similar usage like find. > > > > for example, > > > > Model.pagindate :include => [], :conditions =>[], :group => xx, :order > > => > > xx, :page => xx. > > > > Very simple, isn''t it? :) Hope it''s helpful. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2008-Jan-20 19:02 UTC
Re: Will_paginate and :conditions or :select with associations
But this is what I am doing now to do the fix, but this is not DRY anymore. @values = Bug.paginate(:page => params[:page], :per_page=>30, :select => select_statement, :conditions =>["diripa = ?", @client.dirip]) I have the client.bugs method in my model, I would not have to do this. I didn''t have to do this with the classic pagination. Gr :( sishen wrote:> On Jan 21, 2008 1:06 AM, Damaris Fuentes > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> Client.find_by_dirip(self.diripa) >> conditions... how could I with will_paginate? :( > Bug.paginate :include => [:client], :conditions => [''client_id = ?'', > client.id]-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sishen
2008-Jan-20 19:12 UTC
Re: Will_paginate and :conditions or :select with associations
Can you accept this? class Client < ActiveRecord::Base has_many :bugs do def paginate(options) Bug.paginate end end end On Jan 21, 2008 3:02 AM, Damaris Fuentes <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > But this is what I am doing now to do the fix, but this is not DRY > anymore. > @values = Bug.paginate(:page => params[:page], :per_page=>30, :select => > select_statement, :conditions =>["diripa = ?", @client.dirip]) > > I have the client.bugs method in my model, I would not have to do this. > I didn''t have to do this with the classic pagination. Gr :( >I already forgot how to use classic pagination yet... -,-> > > sishen wrote: > > On Jan 21, 2008 1:06 AM, Damaris Fuentes > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > >> Client.find_by_dirip(self.diripa) > >> conditions... how could I with will_paginate? :( > > Bug.paginate :include => [:client], :conditions => [''client_id = ?'', > > client.id] > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2008-Jan-20 19:23 UTC
Re: Will_paginate and :conditions or :select with associations
Um, no. The problem is that I cannot use the default "has_many" association. I have to state my own "bugs" method cause I''m working with a legacy database, and the primary and foreign key columns are not using the Rails convention. This is why I have something like: class Client < ActiveRecord::Base def bugs Bug.find_all_by_diripa(self.dirip) end end Perhaps will_paginate would work fine if I used conventional associations, but I must do my own methods (in fact, I post a thread with no useful answers with this keys problem [1]). Thanks for your patience. [1] http://www.ruby-forum.com/topic/138796 sishen wrote:> Can you accept this? > > class Client < ActiveRecord::Base > has_many :bugs do > def paginate(options) > Bug.paginate > end > end > end > > On Jan 21, 2008 3:02 AM, Damaris Fuentes > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> >> But this is what I am doing now to do the fix, but this is not DRY >> anymore. >> @values = Bug.paginate(:page => params[:page], :per_page=>30, :select => >> select_statement, :conditions =>["diripa = ?", @client.dirip]) >> >> I have the client.bugs method in my model, I would not have to do this. >> I didn''t have to do this with the classic pagination. Gr :( >> > I already forgot how to use classic pagination yet... -,--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---