# Check if association cached without hitting db?

**URL:** <https://www.ruby-forum.com/t/check-if-association-cached-without-hitting-db/177548>\
**Category:** Rails\
**Created:** [October 20, 2009, 1:35am UTC](https://www.ruby-forum.com/t/check-if-association-cached-without-hitting-db/177548 "2009-10-20T01:35:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [October 20, 2009, 1:35am UTC](https://www.ruby-forum.com/t/check-if-association-cached-without-hitting-db/177548/1 "2009-10-20T01:35:57Z")

</div>

Is there a way to tell if an association on an object is cached without  
hitting the db?

For example, let’s say I have order has\_many line\_items, is there a way  
for me to tell if order.line\_items is already populated?

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [October 20, 2009, 9:19am UTC](https://www.ruby-forum.com/t/check-if-association-cached-without-hitting-db/177548/2 "2009-10-20T09:19:38Z")

</div>

On Oct 20, 12:35 am, Raymond O’Connor \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> Is there a way to tell if an association on an object is cached without  
> hitting the db?
> 
> For example, let’s say I have order has\_many line\_items, is there a way  
> for me to tell if order.line\_items is already populated?

I think you can do order.line\_items.loaded?

Fred
