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.
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:
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.
You are totally correct, it really does what you said, which is the best solution. But I too share your problem:
TextPost
andPicture
have comments (which I'd like to eagerly load), andSpreadSheet
has collaborators, which I'd also like to eagerly load.Yeah, but thats exactly what I wanted to avoid doing. My model is this message board:
A
User
hasFeedItem
s. Each feed item is polymorphically related to one other model object e.g.TextPost
,Picture
,File
,SpreadSheet
and many more, viaFeedItem
'spostable
polymorphic propertySo the problem here is with
FeedItem
: When showingUser
'sFeedItems
, I want to do something like:But since
postable
is polymorphic, i cant and i get the n+1 problem...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.