RailsCasts Pro episodes are now free!

Learn more or hide this

Yossi S's Profile

GitHub User: yossi-shasho

Comments by Yossi S

Avatar

You are totally correct, it really does what you said, which is the best solution. But I too share your problem: TextPost and Picture have comments (which I'd like to eagerly load), and SpreadSheet has collaborators, which I'd also like to eagerly load.

Avatar

Yeah, but thats exactly what I wanted to avoid doing. My model is this message board:

A User has FeedItems. Each feed item is polymorphically related to one other model object e.g. TextPost, Picture, File, SpreadSheet and many more, via FeedItem's postable polymorphic property

So the problem here is with FeedItem: When showing User's FeedItems, I want to do something like:

ruby
@feed_items = current_user.feed_items.includes(:postable)

But since postable is polymorphic, i cant and i get the n+1 problem...

Avatar

Great episode! But I was hoping you'd touch eager loading with polymorphic associations. I couldn't find good information about it, and I feel it's a common problem.