Rails - Single Table Inheritance or not for Applic

2020-05-03 11:08发布

I am am developing a recruitment application for storing records of people who come for an interview. So I have two models - Applicant & Employee which seem like one in OO sense. i.e. Employee was earlier an applicant. Therefore I am planning to create a Single table inheritance like:

Applicant < Person

Employee < Person

All the fields of Applicant are there in Employee. Employee has several other fields that are not in Applicant.

Am I correct with this plan. I have another similar scenario to deal with - prospects & clients.

Update: As I am working more and more with STI, I am starting to dislike it.

1条回答
贼婆χ
2楼-- · 2020-05-03 12:06

As per my personal opinion , in OO point of view you are correct.

Applicant < Person

Employee < Person

But when it comes to database/ tables i will go for a one table called 'persons' (Person) that has all the columns for both 'Applicant' and 'Employee' and have a column with a flag indicating whether the Person is an Applicant or Employee

NOTE :: but this is only true if you have ONLY 'several other fields' not many

HTH

sameera

查看更多
登录 后发表回答