SO I have a table team
team(id, name, parentId).
I have table team as follows:
id name parentId
1 root null
2 child1 1
3 child2 2
SO, I have teamId= 1 I can get the team with teamId 1 along with subteams of teamId 1 with the help of parentId.But is it possible to get the child2 because its the subchild of child1 which is the child of root i.e. teamId 1, with just the teamId information ? Or to make it easier does the table need to be created differently like Teams, Subteams and TeamSubteam with many to many relation ?
Team.find({
where: {
or: [{
id: teamId
}, {
parentId: teamId
}]
},
fields: ['id']
}, function (err, teams) { });