Rails - Single Table Inheritance or not for Applicant/Employee relationship

好久不见. 提交于 2019-12-02 19:14:56

问题


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:


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



来源:https://stackoverflow.com/questions/5701178/rails-single-table-inheritance-or-not-for-applicant-employee-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!