# Polymorphic associations has\_many :through

**URL:** <https://www.ruby-forum.com/t/polymorphic-associations-has-many-through/196903>\
**Category:** Rails I18n\
**Created:** [February 27, 2009, 3:55pm UTC](https://www.ruby-forum.com/t/polymorphic-associations-has-many-through/196903 "2009-02-27T15:55:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![preethi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@preethi](https://www.ruby-forum.com/u/preethi)\
**Post date:** [February 27, 2009, 3:55pm UTC](https://www.ruby-forum.com/t/polymorphic-associations-has-many-through/196903/1 "2009-02-27T15:55:19Z")

</div>

Hi,  
I’m facing an issue in polymorphic associations when i try to to  
:through relationship.  
I’ve three models:profile,gbluser,community

## profile.rb

belongs\_to :node ,:polymorphic =\> true  
belongs\_to :community,:class\_name =\> “community”,  
:foreign\_key =\> “node\_id”,  
:conditions =\> “node\_type = ‘community’”  
belongs\_to :gblorganization,:class\_name =\> “gblorganization”,  
:foreign\_key =\> “node\_id”,  
:conditions =\> “node\_type = ‘gblorganization’”  
has\_and\_belongs\_to\_many :gblusers

## Vcgbluser.rb

has\_many :communities,:through=\>:profiles,:conditions =\>  
“profiles.node\_type = ‘Community’”,:source=\>:community

## Vccommunity.rb

has\_many :gblusers ,:class\_name  
=\>“gbluser”,:through=\>:profiles,:conditions =\> “profiles.node\_type =  
‘Community’”,:source=\>:community

I’m trying to implement has\_many :through relationship between community  
and users.  
user has\_many communities through profiles and  
communities has\_many users through profiles

When i’m trying to do @user.communities, the search is made not on the  
mapping table between user and profiles but on the profile table itself.  
Rails is searching for user\_id in profiles table but i’ve  
has\_and\_belongs\_to\_many between profile and user.  
How to solve this problem? Am I wrong somewhere. Please guide me.  
Thanks
