# Use of Include and Join together

**URL:** <https://www.ruby-forum.com/t/use-of-include-and-join-together/190031>\
**Category:** Rails\
**Created:** [June 11, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/use-of-include-and-join-together/190031 "2010-06-11T18:36:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jschroe212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jschroe212](https://www.ruby-forum.com/u/jschroe212)\
**Post date:** [June 11, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/use-of-include-and-join-together/190031/1 "2010-06-11T18:36:04Z")

</div>

Hello,

I’m wondering if anyone can help me understand what the expected  
behavior would be if i were to use include and joins together on the  
same association. I know from a straight rails perspective that it  
would be a little silly to do since the include will end up doing the  
join at the database level but I’m using a plugin ( searchlogic ) that  
creates named scopes and joins automatically, I’m sure most of you are  
familiar with it.

So I’m using search logic to do a query on an association and also  
displaying that association so to get around the n+1 query I include  
that association. This is resulting in a non-unique table alias bug  
since the join created by searchlogic is giving me an inner join and  
the include is giving me a left outer join both with the same alias.

So basically what I’m trying to figure out is what is the expected  
behavior of joins and includes used together just from a rails  
standpoint and are there any quirks that I could possibly be falling  
into? Hopefully this can help me understand if I have an application  
bug, rails bug, or searchlogic bug.

Thanks in advance!  
James
