# Joining polymorphic tables

**URL:** <https://www.ruby-forum.com/t/joining-polymorphic-tables/133185>\
**Category:** Rails\
**Created:** [March 28, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/joining-polymorphic-tables/133185 "2008-03-28T16:24:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Love\_AJAX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@Love\_AJAX](https://www.ruby-forum.com/u/Love_AJAX)\
**Post date:** [March 28, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/joining-polymorphic-tables/133185/1 "2008-03-28T16:24:22Z")

</div>

Hi,

I have been trying to join a table with another which has got a  
polymporhic set of columns. So I don’t know what would be there in  
“_\_type" column upfront. Moreover the join branches out based on what  
is present in the "_\_type”. For example I have a subscription model  
like this:  
Subscription{:user\_id, :user\_type)

There could be 2 types of users, Family or Friend. And these types of  
users have a login which is stored in logins table.

How can I connect subscriptions table to logins table? My goal is to  
use subscription.family.login if it’s a family user and  
subscription.friend.login if it’s a friend user.

If there was no polymorphic relation then I could’ve said:  
“subscriptions s LEFT JOIN family f ON s.id = f.id”

Thanks  
subbu
