Newbie question about models

I am trying to write a system with tables for engineers and system users. Both are people. It would seem that:

class Person < ActiveRecord::Base belongs_to :job, :polymorphic => true end

class Engineer < ActiveRecord::Base has_one :person, :as => :job end

class SystemUser < ActiveRecord::Base has_one :person, :as => :job end

would be a way of doing that provided that the two groups did not overlap (which of course they do). I am not at all keen to have engineer and system user attributes in the person table.

I am sure there is a very simple solution to this but so far research has come up with overly complicated answers. Can anyone point me in the right direction?

Thanks in advance

Henry

Henry Oss wrote:

I am trying to write a system with tables for engineers and system users. Both are people. It would seem that:

class Person < ActiveRecord::Base belongs_to :job, :polymorphic => true end

class Engineer < ActiveRecord::Base has_one :person, :as => :job end

class SystemUser < ActiveRecord::Base has_one :person, :as => :job end

Waiiiit...engineers and system users are *jobs*? That's what your associations would seem to say, unless I'm misreading.

would be a way of doing that provided that the two groups did not overlap (which of course they do). I am not at all keen to have engineer and system user attributes in the person table.

Do engineers and system users require different sets of fields in their respective tables? If not, you could just unify them as a single Person class with a role field.

I am sure there is a very simple solution to this but so far research has come up with overly complicated answers. Can anyone point me in the right direction?

Thanks in advance

Henry

Best,

Marnen

Thanks for the reply.

Waiiiit...engineers and system users are *jobs*? That's what your associations would seem to say, unless I'm misreading.

Yes. Though perhaps role is a better choice of word.

Do engineers and system users require different sets of fields in their respective tables?

Yes. So many that I don't want to have redundant fields in a single table

Henry

Why? The simplest solution is usually the best. How many million users will you have if disc space is your worry? You might want to look at STI if you want to keep the types functionally distinct, though again the simplicity of an all in one table with a role is usually preferable. You will easily find a plugin that will handle roles for you to make life even easier. The less code you write the fewer bugs you will have and the easier it will be to code, test and maintain.

Colin