0

If I use STI, I'll have several nil columns on my DB and I don't know if I can use Polymorphic Associations in cases like that. Any tip or some references?

[!How the right way to modeling somethink like that?] [1][1]

4
  • Why do you have nil columns? For which of the models in the image do you consider STI or Polymorphoc Associations? Commented Mar 25, 2020 at 16:55
  • Cause if I create a main class with all attributes, theres a child classes that doesn't needs all attributes, then in that classes, these attributes will be nil. Commented Mar 25, 2020 at 19:49
  • But looking at your datamodel both junior and senior have the exact same attributes. What columns do you expect to be nil? Commented Mar 25, 2020 at 21:00
  • Im talking about classes before junior and senior. The classe Employee(junior and senior) in not a problem. The problem is the classes before that contains the same attributes and one more. How I design that classes without repeat the same attributes in all that? For example, classes Lider and Coordenador have the same attributes and one more. Commented Mar 28, 2020 at 17:57

1 Answer 1

1

Though I don't understand the language completely from the image. If I understand I think one Coordinator has many Junior employee and senior employee. And seems like both employee table has the same type of column. What I would do in this case is, I would just create one employee table and keep a enum column of role. The model would look something like below-

class Coordinator
 has_many: :employees
end

class Employee
 belongs_to: :coordinator

 enum role: { junior: 0, senior: 1 }
end

If you haven't used enum in Rails yet, it's really handy. Take a look

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is not Cordinator class, its ok. The problem is with the classes before that contains the same attributes with one or two more. How can I design it without repeat all attributes in every class?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.