How can I use Pagination on Model associations?


#1

I have the following code

@components_pages = Paginator.new self,
Computer.find(params[:id]).components.count,
2, @params[‘page’]

How can I restrict find to only return associations(components) for the
current page?
@computer = Computer.find(params[:id] …

I spent a few hours thinking about this one but to no avail

regards,
Leon.


#2

I also has this problem and solved it by using conditions (accroding to
the
associaltions) in the paginate definition. But I i don’t think this is a
nice solution. Are there better ways of doing that ?

regards

On 11/17/05, Leon L. removed_email_address@domain.invalid wrote:

I spent a few hours thinking about this one but to no avail


Roberto S. - http://rsaccon.com


#3

Hi Saccon,

Thanks for your quick reply to the post.

Do you have an example?

It would be cool if one could limit includes in associations, but this
is
just my mad method of thinking. Can i have a view of your conditions and
how
you did it?

regards,
Leon.


#4

Computer.find(:first,
:conditions => [“id=?”, params[:id]]).components.count


or
Computer.find(:first,
:conditions => [“id=? and price>?”, params[:id],
3000]).components.count

i hope that’s make sense.