squeel icon indicating copy to clipboard operation
squeel copied to clipboard

eager loading polymorphic associations

Open the8472 opened this issue 12 years ago • 3 comments

.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

the8472 avatar Jul 31 '13 18:07 the8472

Correct.That's intentional, though. Not really sure what the desired outcome would be on this one?

ernie avatar Jul 31 '13 18:07 ernie

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.

the8472 avatar Jul 31 '13 21:07 the8472

:+1: I really want this feature.

odiak avatar Sep 05 '14 09:09 odiak