MorphMany or multiple manyToMany
Hi!
I need help structuring adding comment feature
DB schema for part of the app, there are aprox 20 more tables
departments
id - integer
name - string
...
users
id - integer
name - string
...
events
id - integer
title - string
...
goals
id - integer
goal - string
...
Relationships
Department hasMany Users
User hasMany Events
Event many To many goals
I now want to add the feature comments. PolyMorphic would be easy to add comments on department, user.
But it should be possible to comment on goals, and I want the comment to be associated to the user. So that other users can not see these comments. Should be private to the user.
Strategies. 1. Add extra column with user_id to the commentable table
commentable
comment_id - `foreignId('comments')->constrained()`
commentable_id - integer (ID of goal, event, department, user)
commentable_id_type - string (Model name, like "App\Models\Goal")
user_id - foreignId('users')->constrained()`
With the risk that this will involve more complexity to the code, will it work with laravel Eloquent, or will it need Raw SQL querys.
Or Separate the comments for eg goal and some other table that have more complex ralation to user and make manyToMany relationships and more tables.
Suggestions, previous experience to share?
Thx in advance! Tobias
Please or to participate in this conversation.