# IS A relationship in rails and additional field in Join tabl

**URL:** <https://www.ruby-forum.com/t/is-a-relationship-in-rails-and-additional-field-in-join-tabl/138150>\
**Category:** Rails\
**Created:** [May 20, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/is-a-relationship-in-rails-and-additional-field-in-join-tabl/138150 "2008-05-20T17:02:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [May 20, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/is-a-relationship-in-rails-and-additional-field-in-join-tabl/138150/1 "2008-05-20T17:02:19Z")

</div>

Hello,  
I have a couple of questions:

1. How to implement IS A relationship

2. For the time being, I have defined has\_many :through relationship  
between people and events. In the join table I want to store the TOPIC  
that the speaker will speak in the event. So how can i store it from the  
form.

so the join table should look like  
person\_id event\_id Topic  
Thank you.

---

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [May 20, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/is-a-relationship-in-rails-and-additional-field-in-join-tabl/138150/2 "2008-05-20T18:42:10Z")

</div>

The answer depends on whether or not ‘speaker’ is a special kind of  
person that has certain attributes and abilities that only a speaker  
has. If that is the case then you can subclass using Single Table  
Inheritance by adding a ‘type’ column to your people table and  
implementing the Speaker class like this:

class Person \< ActiveRecord::Base  
…general person kinds of things…  
end

class Speaker \< Person  
…special speaker stuff…  
end

The “\<” in the class definition indicates it’s inheritance. And, yes,  
that means Person IS A extension of the ActiveRecord::Base class.

Now, if your intention is only to say “the speaker at this event is  
that particular person over there” then you can do this:

class Event \< ARec::Base  
belongs\_to :speaker, :class\_name=\>‘Person’  
end

As show you’ll need a ‘speaker\_id’ column on the event. You could  
also make it ‘person\_id’ if you prefer, but you’ll need to  
add :foreign\_key=\>‘person\_id’ to the belongs\_to invocation. Either  
way, this means you can call the person associated with the event the  
‘speaker’ in the context of the Event.
