views:

16

answers:

1

The following result sets work well with will_paginate:

Members.all(:limit => 5).paginate(:page => params[:page])
Members.all(:conditions => ["member_no < 6"]).paginate(:page => params[:page])
Members.all.paginate(:page => params[:page])

The following does not:

Members.all(:conditions => ["member_no IN (?)", [1, 2, 3, 4, 5]]).paginate(:page => params[:page])

Why the second query does not work well with paginate? Thanks!

A: 

The #paginate is an instance method made available on Array and ActiveRecord::Base. You really should be doing it this way:

Member.paginate(:page => params[:page], :limit => 5)
Member.paginate(:conditions => ["member_no < ?", 6], :page => params[:page])
Member.paginate(:page => params[:page])
Member.paginate(:conditions => {:member_no => (1..5)}, :page => params[:page])

When you call #all then #paginate, what you're doing is asking for all members (all 1,000,000 of them), then discarding 99.999% of them, because you only want the first 10. This is very wasteful, to say the least.

François Beausoleil