will_paginate icon indicating copy to clipboard operation
will_paginate copied to clipboard

EagerLoadPolymorphicError being thrown whenever conditions used

Open ghost opened this issue 13 years ago • 3 comments

I am running will_paginate 3.0.pre2 on rails 3.0.7, and there seems to be some type of strange bug where a EagerLoadPolymorphicError is being raised whenever almost any conditions are used.

My 2 relevant models are very simple: class Book boolean public belongs_to :author, :polymorphic => true end class Individual has_many :books, :as => :author end class Group has_many :books, :as => :author end

This query will raise the exception: Book.where(:public => true).includes(:author).paginate(:page => @page, :per_page => page_size, :order => "id DESC")

I have tried modifying the condition in a number of ways, and the only way that makes it not throw an exception is if the condition is on the id column, oddly enough.

ghost avatar May 16 '11 06:05 ghost

Looks like an Active Record bug. Can you try again with latest will_paginate from master branch and Rails 3.0.9? Thanks

mislav avatar Aug 09 '11 12:08 mislav

I just tried on Rails 3.0.9 with will_paginate 3.0.0 and the bug still behaves the same.

Book.where(:public => true).includes(:author).limit(10).order(:id) works correctly. Book.where(:public => true).includes(:author).paginate(:page => 1, :per_page => 10, :order => :id) fails Book.where(:id => [1,2,3]).includes(:author).paginate(:page => 1, :per_page => 10, :order => :id) works correctly.

ghost avatar Aug 09 '11 15:08 ghost

Thanks for all the info. I will try to work around the bug. The current test suite doesn't have polymorphic associations, so this went undetected.

mislav avatar Aug 09 '11 17:08 mislav