Rapid loading of polymorphic association with pagination Kaminara

I try to load the polymorphic association and also paginate it using the Kaminari gem:

@news_items = NewsItem.includes(:news_source).not_outdated
.where(:group_id => group_ids).order("created_at DESC").page(params[:page]).per(10)

I get an error message:

ActiveRecord :: EagerLoadPolymorphicError in the Pages panel

Display "BLAH BLAH" /dashboard.html.erb where line number 49 is raised: cannot look forward to the polymorphic association: NEWS_SOURCE

When I delete the Kaminari area (.page [: page]). per (10)), then the error disappears.

Does anyone have any ideas? This article suggests that active loading using polymorphic associations is supported, but only if the conditions / order that can be applied to the relation as a region, t refers to any other tables (if they do, then Rails uses the LEFT OUTER JOIN method for active boot, which cannot work with polymorphic associations). So: Kaminari refers to another table?

Would thank for any advice!

Greetings.

+3
source share
1 answer

You should always use preloadfor polymorphic associations.

- , includes eager_load, , preload.

0

All Articles