-
Hello folks 👋 I'm confused about defining relationships by my User model's role. I've a enum type that contains 'admin', 'designer', 'staff' elements and used for User's role column type. Is there any solution except creating models by these roles? Thanks already. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
First thought at Controller/Business logic level you can check role to inset/update receptive relationship also at api json serialization based on role you can only pull that of specific user role conditional relationship On Second thought only possible (guessing/speculation) alternative is to use override but here loading data from table row then using |
Beta Was this translation helpful? Give feedback.
-
If you have a fixed amount of roles (lets say 3 in your case), create models for each role (admin, designer, staff) which includes specific data for each role In your controllers: Example: User (Designer) -> DesignerProfile -> Design If this is too much abstraction, you could just assign all relationships to the user model and only query each when needed. |
Beta Was this translation helpful? Give feedback.
If you have a fixed amount of roles (lets say 3 in your case), create models for each role (admin, designer, staff) which includes specific data for each role
For every role, assign its related relationship (design, staffImage, etc.)
In your controllers:
Check for the role of user (admin, designer, staff) and then fetch its role-model instance and then fetch the related data to the role
Example:
User (Staff) -> StaffProfile -> StaffImage
User (Designer) -> DesignerProfile -> Design
If this is too much abstraction, you could just assign all relationships to the user model and only query each when needed.