# Chained Polymorphic Association and the missing type field

**URL:** <https://www.ruby-forum.com/t/chained-polymorphic-association-and-the-missing-type-field/176146>\
**Category:** Rails\
**Created:** [September 25, 2009, 9:41am UTC](https://www.ruby-forum.com/t/chained-polymorphic-association-and-the-missing-type-field/176146 "2009-09-25T09:41:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![swoolley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@swoolley](https://www.ruby-forum.com/u/swoolley)\
**Post date:** [September 25, 2009, 9:41am UTC](https://www.ruby-forum.com/t/chained-polymorphic-association-and-the-missing-type-field/176146/1 "2009-09-25T09:41:59Z")

</div>

I have a chained polymorphic relationship. I will try to describe it  
as best as I can.

Imagine:

```
    Group (polymorphic)
            \
             |
           Tag (polymorphic)
               \
               |
              Article

```

The idea being I can TAG many ARTICLES. I can also GROUP many TAGS.  
And enjoy using both TAG and GROUP in more creative ways. I also use  
proxy classes (GROUPABILITY and TAGABILITY) to encapsulate the  
relationships. Both Groupability and Tagability are where  
the :polymorphic =\> true statement resides. Then I use has\_many with  
a :through statement to do most of the relational work.

```
    Group
            \
             > Groupability (real polymorphic)
             |
           Tag
               \
               > Tagability (real polymorphic)
               |
              Article

```

After creating this relationship, the Tagabilty works just fine. The  
Tagable\_id and Tagable\_type field are populated correctly. The  
Groupability appears to work fine HOWEVER while the groupable\_id field  
is populated correctly , the groupable\_type field remains nil. I  
(believe) I have checked all my syntax which looks correct.

Are there any known bugs with this type of chained polymorphism or  
some trick I am missing? Is the belongs\_to on the polymorphic =  
true line, simply appended with “\_type” to determine the proper field  
in the database to set the value? Is there a manual way of setting the  
\_type field for the proper class? How can I debug this when I am  
getting no errors?

Steve Woolley  
removed\_email\_address@domain.invalid
