# Polymorphic association question

**URL:** <https://www.ruby-forum.com/t/polymorphic-association-question/183098>\
**Category:** Rails\
**Created:** [February 8, 2010, 5:01am UTC](https://www.ruby-forum.com/t/polymorphic-association-question/183098 "2010-02-08T05:01:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [February 8, 2010, 5:01am UTC](https://www.ruby-forum.com/t/polymorphic-association-question/183098/1 "2010-02-08T05:01:49Z")

</div>

This is an example from the geokit plugin which I am trying to  
reproduce.

class Location \< ActiveRecord::Base  
belongs\_to :locatable, :polymorphic =\> true  
acts\_as\_mappable  
end

class Company \< ActiveRecord::Base  
has\_one :location, :as =\> :locatable # also works for belongs\_to  
associations  
acts\_as\_mappable :through =\> :location  
end

We see two separate models here. Now is there also a third model, like  
some kind of join table? Also is there a locatable\_id:integer and  
locatable\_type:string as well?

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [February 8, 2010, 3:51pm UTC](https://www.ruby-forum.com/t/polymorphic-association-question/183098/2 "2010-02-08T15:51:59Z")

</div>

The polymorphic :locatable association implies a :locatable\_type and  
:locatable\_id column. These columns reference a row in an arbitrary  
table  
identified by :locatable\_type so no join table is needed.

On Feb 7, 2010 11:02 PM, “Sean S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

This is an example from the geokit plugin which I am trying to  
reproduce.

class Location \< ActiveRecord::Base  
belongs\_to :locatable, :polymorphic =\> true  
acts\_as\_mappable  
end

class Company \< ActiveRecord::Base  
has\_one :location, :as =\> :locatable # also works for belongs\_to  
associations  
acts\_as\_mappable :through =\> :location  
end

## We see two separate models here. Now is there also a third model, like some kind of join table? Also is there a locatable\_id:integer and locatable\_type:string as well?

Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
You received this message because you are subscribed to the Google  
Groups  
“Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
