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.

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.

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? :slight_smile: Hope it’s helpful.

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? :frowning:

Thanks.

sishen 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? :frowning:
Bug.paginate
:include => [:client], :conditions => [‘client_id = ?’, client.id]

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 :frowning:

sishen wrote:

Can you accept this?

class Client < ActiveRecord::Base
has_many :bugs do
def paginate(options)
Bug.paginate
end
end
end

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 :frowning:
I already forgot how to use classic pagination yet… -,-