Avoid re-finding already-loaded associations

I have a situation where an instance method pulls out a selection from a set of associated objects. Sometimes when this is called the associated objects have been eager loaded, in which case it makes most sense to use .select to pull the ones i want from the already-loaded collection. Other times the associated objects have *not* been eager loaded, and it makes most sense to use association.find to get the ones i want.

My question is this: can i tell if the associated objects have been eager loaded already, so i can choose which approach to take? Or, even better, is there a single approach where rails will know whether to load them again or not?

thanks, max

I have a situation where an instance method pulls out a selection from a set of associated objects. Sometimes when this is called the associated objects have been eager loaded, in which case it makes most sense to use .select to pull the ones i want from the already-loaded collection. Other times the associated objects have *not* been eager loaded, and it makes most sense to use association.find to get the ones i want.

My question is this: can i tell if the associated objects have been eager loaded already, so i can choose which approach to take? Or, even better, is there a single approach where rails will know whether to load them again or not?

if it's a collection then foo.bars.loaded?

Fred

ahh yes. perfect. thanks for the thousandth time Fred :slight_smile: