Page Count wrong and whacky with complex query.. #26

Closed
sblackstone opened this Issue Feb 4, 2010 · 3 comments

Comments

Projects
None yet
4 participants

Here's the actual call to AR:
@hidden_topics = @band.topics.most_hidden_since(hidden_topics_date).paginate :page => params[:page]

Here's the named scope:
named_scope :most_hidden_since, lambda {|since| {
:joins => :hidden_topics,
:having => 'count(hidden_topics.id) > 0',
:group => 'topics.id',
:conditions => ['created_at > ?', since],
:order => 'count(hidden_topics.id) desc' } }

(This mess sorts by the count of the has_many association)

The page count was 7 on some pages and 4 on others.. The Patch that was posted here last march fixed my problem :

http://groups.google.com/group/will_paginate/browse_thread/thread/3b902e23e01e1ec9?pli=1

Thanks.

lwille commented Feb 22, 2010

Executing a named_scope and paginating afterwards is quite ineffective, as it uses Array.paginate on the complete result set (38k records in my case).

Take a look at http://bit.ly/aOAgxb (will_paginate google group) and try using proxy_options and some merging to build the options hash for paginate.

Just wanted to throw in a 'me too'. I see this happening with scopes in rails 3.0.3.

Owner

mislav commented Aug 9, 2011

named_scope + paginate bugs are usually in Active Record and there is little I can do about them. The best I can advise is upgrade Rails version and will_paginate to latest version. For instance, use will_paginate 2.3.16 with Rails 2.3.12, or will_paginate 3.0 with Rails 3 or higher. If such bugs persist and are really nasty, add more info to this ticket.

Closing

@mislav mislav closed this Aug 9, 2011

egiblin pushed a commit to egiblin/will_paginate that referenced this issue Feb 22, 2017

Merge pull request #26 from tbarto/master
create action updated so post request works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment