# Polymorphic associations wrong when used with inherited class?

**URL:** <https://www.ruby-forum.com/t/polymorphic-associations-wrong-when-used-with-inherited-class/134558>\
**Category:** Rails\
**Created:** [April 12, 2008, 12:29am UTC](https://www.ruby-forum.com/t/polymorphic-associations-wrong-when-used-with-inherited-class/134558 "2008-04-12T00:29:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaredmoody](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@jaredmoody](https://www.ruby-forum.com/u/jaredmoody)\
**Post date:** [April 12, 2008, 12:29am UTC](https://www.ruby-forum.com/t/polymorphic-associations-wrong-when-used-with-inherited-class/134558/1 "2008-04-12T00:29:26Z")

</div>

Consider the following:

class Event  
belongs\_to :event\_object, :polymorphic =\> true  
end

class Asset \< ActiveRecord::Base  
end

class EventedAsset \< Asset  
has\_one :event, :as =\> :event\_object  
end

EventedAsset.find(:first).event generates the following SQL:

SELECT \* FROM `events` WHERE (events.event\_object\_id = 1 AND  
events.event\_object\_type = ‘Asset’) LIMIT 1

shouldn’t this be:

SELECT \* FROM `events` WHERE (events.event\_object\_id = 1 AND  
events.event\_object\_type = ‘EventedAsset’) LIMIT 1

---

<div class="post-metadata">

**Author:** ![jaredmoody](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@jaredmoody](https://www.ruby-forum.com/u/jaredmoody)\
**Post date:** [April 12, 2008, 12:47am UTC](https://www.ruby-forum.com/t/polymorphic-associations-wrong-when-used-with-inherited-class/134558/2 "2008-04-12T00:47:37Z")

</div>

I guess i should RTFM.

(here for anyone with the same problem:  
[Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html))

Still, IMO, you shouldn’t have to define a crazy method like:

def attachable\_type=(sType)  
super(sType.to\_s.classify.constantize.base\_class.to\_s)  
end

to make STI work with polymorphic associations, it should “just work,”  
like everything else does in rails.
