# Polymorphic assc. uses base\_class of object instead of class

**URL:** <https://www.ruby-forum.com/t/polymorphic-assc-uses-base-class-of-object-instead-of-class/72920>\
**Category:** Rails\
**Created:** [October 19, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/polymorphic-assc-uses-base-class-of-object-instead-of-class/72920 "2006-10-19T22:17:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [October 19, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/polymorphic-assc-uses-base-class-of-object-instead-of-class/72920/1 "2006-10-19T22:17:17Z")

</div>

Example:

class User \< ActiveRecord::Base  
end

class Member \< User  
has\_one :blog, :as =\> :blogable  
end

class Blog \< ActiveRecrod::Base  
belongs\_to :blogable, :polymorphic =\> true  
end

The member.blog.blogable\_type is ‘User’.  
Does anybody know the reasoning for using the base\_class instead of the  
class name of the object

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [November 22, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/polymorphic-assc-uses-base-class-of-object-instead-of-class/72920/2 "2006-11-22T22:58:35Z")

</div>

Chris M. wrote:

> The member.blog.blogable\_type is ‘User’.  
> Does anybody know the reasoning for using the base\_class instead of the  
> class name of the object

The reason is that the RDBMS needs to do joins on the actual table,  
which corresponds to the base class, not the non-existent STI child  
class.

Evan

---

<div class="post-metadata">

**Author:** ![johan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@johan](https://www.ruby-forum.com/u/johan)\
**Post date:** [October 20, 2006, 12:33am UTC](https://www.ruby-forum.com/t/polymorphic-assc-uses-base-class-of-object-instead-of-class/72920/3 "2006-10-20T00:33:55Z")

</div>

johan wrote:

> belongs\_to :blogable, :polymorphic =\> true  
> end
> 
> The member.blog.blogable\_type is ‘User’.  
> Does anybody know the reasoning for using the base\_class instead of the  
> class name of the object

The STI/Polymorphic thing is a bit of a mess at the moment, as I  
understand it. This recent documentation patch:

[http://dev.rubyonrails.org/changeset/5259](http://dev.rubyonrails.org/changeset/5259)

contains some info that might help you for now.

Chris
