# Nil results caching in belongs\_to association

**URL:** <https://www.ruby-forum.com/t/nil-results-caching-in-belongs-to-association/67715>\
**Category:** Rails\
**Created:** [September 6, 2006, 9:51am UTC](https://www.ruby-forum.com/t/nil-results-caching-in-belongs-to-association/67715 "2006-09-06T09:51:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@dimon](https://www.ruby-forum.com/u/dimon)\
**Post date:** [September 6, 2006, 9:51am UTC](https://www.ruby-forum.com/t/nil-results-caching-in-belongs-to-association/67715/1 "2006-09-06T09:51:04Z")

</div>

Someone wrote here that nil :include results are cached with has\_one  
association in edge rails. I can’t get edge rails at the moment, so  
could anybody answer please if nil results are cached with belongs\_to  
associations. This means that when u perform find with :include =\>  
belongs\_to\_association and the result of generated LEFT OUTER JOIN is  
nil, rails doesn’t generate sql query SELECT \* FROM  
when using method found\_object.belongs\_to\_association  
At the moment I have to use query like this in my model to get the same  
result:

def self.get\_associations( id, association )  
find( :all,  
:joins =\> “JOIN #{association} ON #{association}.key =  
model\_table.\_key”,  
:include =\> association,  
:conditions =\> [“model\_table.key = ‘?’”, id],  
)  
end

And I have to run it in a iteration for each association instead of  
selecting all associations in one query :((

Thanks,  
Dmitry
