# Use of :include option in find query

**URL:** <https://www.ruby-forum.com/t/use-of-include-option-in-find-query/193052>\
**Category:** Deployment\
**Created:** [August 10, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/use-of-include-option-in-find-query/193052 "2010-08-10T14:43:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 10, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/use-of-include-option-in-find-query/193052/1 "2010-08-10T14:43:34Z")

</div>

Hi,  
I have a Person model and Company model like as follows:-

Person.rb

class Person \<ActiveRecord::Base  
has\_one :company  
end

Company.rb  
class Company \< ActiveRecord::Base  
end

I have a function  
def person\_details  
@person=Person.find(params[:id, :include=\> :company)  
end

person\_details.html.erb  
\<%=@person.name%\> : \<%=@person.company.name%\>

I read that if you use the :include option then it reduces your number  
of queries.  
Means, whenever it is firing a query to find person same time it eager  
loads the company association.

I am confused that what exactly it does? Is it load the company object  
in memory? and instead of going to database it takes it from memory.

Can anyone elaborate me what exactly happens when we use the :include  
option.

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 10, 2010, 2:45pm UTC](https://www.ruby-forum.com/t/use-of-include-option-in-find-query/193052/2 "2010-08-10T14:45:07Z")

</div>

Sorry for posting the question in Rails deployment section. I have added  
in Ruby On Rails section.  
Mike D. wrote:
