Single table inheritance

I’m having a class called Person, with subclasses as goalkeeper,
forward, defender.

Now a person can be a forward as well as a defender or a goalkeeper.

I want to use single table inheritance like :

class Goalkeepr < Person
end

And not have multiple boolean columns like in my people table like is
is_goalkpeer, is_forward, is_defender.

How do I go about it ?

Thanks,
Pratik

rm -rf / 2>/dev/null - http://null.in

“Things do not happen. Things are made to happen.” - JFK

If you create a column ‘type’ in your table, ActiveRecord should
magically make STI work.

Tom

Right. I understand that. But in case of ‘type’ driven STI, a person
can just have one type. I don’t want to use HABTM with roles because I
want to seperate logic for different type of people.

I’m looking for something that lets me scope the inherited table
instead of using type field. Something like :

class Goalkeeper < Person
:scope => “type_id = 4”
end

Probably something like
http://roman2k.free.fr/rails/meantime_filter/0.1.0/rdoc/ for models.

Thanks,
Pratik

On 7/6/06, Tom W. [email protected] wrote:

Thanks,


email : tom at popdog.net


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


rm -rf / 2>/dev/null - http://null.in

“Things do not happen. Things are made to happen.” - JFK

On 7/6/06, Pratik [email protected] wrote:

And not have multiple boolean columns like in my people table like is
is_goalkpeer, is_forward, is_defender.

Hi Pratik,
I guess you have no way to use the STI in this scenario. I’d go with a
Person model that contains all the data except the role and create a
Role model/table.
Then Role belongs_to Person and Person has_many Roles.
Cheers.

On Thursday, July 06, 2006, at 10:48 PM, Francesco Levorato wrote:

francesco levorato aka flevour
http://www.flevour.net/


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

For this type of thing, I use the acts_as_taggable plugin. Then you can
tag each person with each role that they fulfill and you won’t clutter
up your model with extraneous fields.

_Kevin

On 7/6/06, Pratik [email protected] wrote:

And not have multiple boolean columns like in my people table like is
is_goalkpeer, is_forward, is_defender.

Hi Pratik,
I guess you have no way to use the STI in this scenario. I’d go with a
Person model that contains all the data except the role and create a
Role model/table.
Then Role belongs_to Person and Person has_many Roles.
Cheers.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs