Does anyone know a way to determine if a Rails association has been eager loaded?
My situation: I have a result set where sometimes one of the associations is eager l
item.shipping_infos.loaded?
will tell you.
I gotta say, though: this path leads to madness... before writing code that tests loaded?
to decide between #detect
and #find
, make sure this instance really matters, relative to everything else that's going on.
If this isn't the slowest thing your app does, adding extra code paths adds unnecessary complexity. Just because you might waste a little database effort doesn't mean you need to fix it - it probably doesn't matter in any measurable way.