eager loading polymorphic associations
.preload takes keypaths in its DSL form, but it doesn't seem to handle the type discriminators on polymorphic associations:
ModelA.preload do
[
something_polymorphic(SpecificTypeB).relation_only_available_on_that_type,
something_polymorphic.available_on_all
]
end
Correct.That's intentional, though. Not really sure what the desired outcome would be on this one?
UI iterates over instances of ModelA but needs to fetch some additional data from the associations. The views specialize each entry based on the polymorphic type, and the one for SpecificTypeB needs another relation.
So it's to avoid N+1 queries.
This wouldn't be necessary if there was some "take all these objects and bulk-load association X on all of the already-loaded instances" logic. But that doesn't seem to exist as far as I can see.
:+1: I really want this feature.