Forum: Ruby on Rails Polymorphic association question

Posted by Sean Six (seansix)
on 2010-02-08 05:01
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 by Mat Brown (Guest)
on 2010-02-08 15:51
(Received via mailing list)
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 Six" <lists@ruby-forum.com> 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/.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com<rubyonrails-talk%2Bunsubscribe@googlegroups.com>
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.