I have a trouble need your helps:
There are 1 model Employee with 1 attribute “employee_type”. One employee only has one type. There are 3 types of employee (“beginner”, “normal”, “pro”, maybe increase in the future). So I think there are 3 ways to implement it.
- employee_type attribute is string type, it is “beginner”, or “normal”, or “pro”. Then in helper, I need define method for display 3 type in select box view. With this way, disadvantage is “whenever I want to add more type, I must insert in raw code”
- Create employee_type table with only 3 record “beginner”, “normal”, “pro”. And employee_type attribute is integer type, which save id of employee_type table’s record. employee table and employee_type table haven’t any association. With this way, advantage is easy to insert more type. Disadvantage is “if I want to find type of employee, I must run EmployeeType.find(employee.employee_type)”
- Create employee_type table, it has relation 1-1 with employee and use has_one. With this way, advantage is easy to find type of employee by employee.employee_type. Disadvantage is hard to manage how many types of employee
Are there any better way than them?
Thank you very much
It’s one-to-many case. You have to use the following scheme: