This question might be related to database schema design in sails.js waterline.
One task need to record different roles of users. For example, a Task
need to know who are fooUsers
and barUsers
in this task. What is the best way to handle this? (foo and bar are different roles for a user)
More Context
- A
User
will have differentRole
s. - The roles of the user might change in the future.
- A
User
will only be oneRole
in oneTask
. - The
Role
of aUser
in a specificTask
will never change. - A
Task
will have many users involved. - All tasks are the SAME type.
- The total number of Roles will NOT change.
For example:
One task has four users: UserA
with Role1
, UserB
with Role2
, UserC
with Role3
, UserD
with Role1
.
In the future, UserA
might have Role2
and Role3
. But that doesn't affect what role of the UserA
is in the above task.
My Final Design
// User.js
attributes: {
tasks: {
collection: 'task',
via: 'users'
},
roles: {
collection: 'role',
via: 'users'
},
userTaskRoles: {
collection: 'userTaskRole',
via: 'user'
}
}
// Task.js
attributes: {
users: {
collection: "user",
via: "tasks"
},
userTaskRoles: {
collection: 'userTaskRole',
via: 'task'
}
}
// Role.js
attributes: {
users: {
collection: 'user',
via: 'roles'
},
userTaskRoles: {
collection: 'userTaskRole',
via: 'role'
}
}
// UserTaskRole.js
attributes: {
task: {
model: 'task'
},
user: {
model: 'user'
},
role: {
model: 'role'
}
}
I updated this question a lot. The above is my final design. Please give me some feedback whether or not this is good or bad and are there any better design patterns?
Thanks.