# How can I retrieve the object on an association without going through the database?

**URL:** <https://www.ruby-forum.com/t/how-can-i-retrieve-the-object-on-an-association-without-going-through-the-database/191053>\
**Category:** Rails\
**Created:** [July 3, 2010, 12:13pm UTC](https://www.ruby-forum.com/t/how-can-i-retrieve-the-object-on-an-association-without-going-through-the-database/191053 "2010-07-03T12:13:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@ken](https://www.ruby-forum.com/u/ken)\
**Post date:** [July 3, 2010, 12:13pm UTC](https://www.ruby-forum.com/t/how-can-i-retrieve-the-object-on-an-association-without-going-through-the-database/191053/1 "2010-07-03T12:13:03Z")

</div>

Consider the following setup:

class Parent \< ActiveRecord::Base  
has\_many :children  
end

class Child \< ActiveRecord::Base  
belongs\_to :parent  
end

And this console session:

> > p = Parent.find 41  
> > p.some\_attr = ‘some\_value’  
> > c = p.children.build  
> > c.parent

By watching my log files, I can see that c.parent is querying the db  
for the parent object. I want instead to access the existing in-memory  
object §, because I need access to the parent’s some\_attr value,  
which is not yet stored in the database. Is there any way of doing  
this? c.parent(force\_reload=false) doesn’t get me there.

---

<div class="post-metadata">

**Author:** ![ken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@ken](https://www.ruby-forum.com/u/ken)\
**Post date:** [July 3, 2010, 1:33pm UTC](https://www.ruby-forum.com/t/how-can-i-retrieve-the-object-on-an-association-without-going-through-the-database/191053/2 "2010-07-03T13:33:42Z")

</div>

are you using rails 3?

If you are I think you just do

p = Parent.includes(:children).find(41)
