0 Best Reply Awards

  • Member Since 6 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

13th March, 2018

davfg left a reply on Inheritance Of Models • 6 months ago

Thank you very much @martinbean for your response. As I understood, you recommend me to create a single user model that has all the attributes of User and Competitor, but I do not understand the relationship of many to many with Team, since only competitors belong to a team, while Managers and Administrators do not. And it would not be bad practice to establish many columns in User that only competitors will use, being the value of these columns for managers and administrators null?

davfg started a new conversation Inheritance Of Models • 6 months ago

Hello, I have a problem when designing my models related to users and their relationships. In my application, I have three types of users: Admin, Manager and team of competitors. The models that I have thought to create so far are:

  • User (parent model): id, name, identifier, password, role_id (refer to a table Roles with three entries: admin, manager, team of competitors), competition_id (reference to a table Competitions).
  • Team: id, school, teacher, email, user_id (reference to the user table)
  • Competitor: id, name, birthday, educationalDegree, team_id (reference to the user table).

It should be mentioned that the attribute "competition_id" in the user table refers to a team of competitors participating in a certain competition, a manager can configure a single competition and an administrator can configure all competitions (set to null for admin) .

My problem arises when I want to relate these models to each other, where I have read that it can be done with polymorphic relationships, but I am not sure about it. I would appreciate any help regarding a new way of designing these models and their relationships or how to design relationships between these models.

Thank you very much for your time.

Edit Your Profile

Want to change your profile photo? We pull from gravatar.com.