I apologise if this is a bit of a stupid or broad question, but I'd like some general feedback please!
Say I have this DB structure for users (in Mongo/JS, but really it's all pseudocode- and the IDs would actually be DB references, not basic integers):
users = [
{
id: 1,
name: 'John Smith'
},
{
id: 2,
name: 'Sheila X. Ample'
}
]
... and I want to define some projects where one or more of these people can be collaborators on it. The project will define who has general access to it as well as who created it, who is the current primary collaborator (this will change regularly), who last updated it, etc etc.
Is this method best, where the IDs are represented directly onto the project object:
projects = [
{
id: 1,
name: 'Project One',
collaborators: [
2
],
primaryCollaborator: 2,
lastUpdatedBy: 2,
createdBy: 2
},
{
id: 2,
name: 'Another Project',
collaborators: [
1,
2
],
primaryCollaborator: 1,
lastUpdatedBy: 2,
createdBy: 1
}
]
// Get the primary collaborator:
primaryID = projects.find({id: 2}).primaryCollaborator;
Or this one, where the properties are booleans on each individual collaborator:
projects = [
{
id: 1,
name: 'Project One',
collaborators: [
{
id: 2,
primaryCollaborator: true,
lastUpdatedBy: true,
createdBy: true
}
]
},
{
id: 2,
name: 'Another Project',
collaborators: [
{
id: 1,
primaryCollaborator: true,
lastUpdatedBy: false,
createdBy: true
},
{
id: 2,
primaryCollaborator: false,
lastUpdatedBy: true,
createdBy: false
}
]
}
]
// Get the primary collaborator:
primaryID = projects.find({id: 2}).collaborators.find({primaryCollaborator: true}).id;
As I said, I'm sure this kind of structural question has been asked a million times before but I wouldn't for the life of me know what to Google to find it!
What are the benefits or drawbacks of doing it in either way? Does it even make a difference? The first method would require that the IDs referenced on the project object existed and would cause a headache if, say, a collaborator was removed from the project. The second method seems a bit weighty and would cause a headache if something went awry and more than one collaborator was classed as being true
as the primary collaborator, for example. Or is there a better method entirely?
Thanks in advance! :)