# Avoid re-finding already-loaded associations

**URL:** <https://www.ruby-forum.com/t/avoid-re-finding-already-loaded-associations/191568>\
**Category:** Rails\
**Created:** [July 14, 2010, 4:30pm UTC](https://www.ruby-forum.com/t/avoid-re-finding-already-loaded-associations/191568 "2010-07-14T16:30:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 14, 2010, 4:30pm UTC](https://www.ruby-forum.com/t/avoid-re-finding-already-loaded-associations/191568/1 "2010-07-14T16:30:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 14, 2010, 4:38pm UTC](https://www.ruby-forum.com/t/avoid-re-finding-already-loaded-associations/191568/2 "2010-07-14T16:38:33Z")

</div>

On Jul 14, 3:30 pm, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> them again or not?

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

Fred

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 14, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/avoid-re-finding-already-loaded-associations/191568/3 "2010-07-14T16:44:50Z")

</div>

ahh yes. perfect. thanks for the thousandth time Fred 🙂
