EagerLoadPolymorphicError being thrown whenever conditions used #129

Open
tomjones-xx opened this Issue May 16, 2011 · 3 comments

Comments

Projects
None yet
2 participants

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.

Owner

mislav commented Aug 9, 2011

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

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.

Owner

mislav commented Aug 9, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment