I am designing a schema for my new application. During this process, I am stuck at one point. Here is my use case.
I have three entities, User, Group, and Company.
They are related to each other as many to many. For example,
User can be a part of multiple companies,
A company can have multiple users.
User + Company can have multiple groups. (User + Company + Group combination should be unique)
Following is SQL schema which represents this relationship
Table: User
UserId Name
1 Alice
2 John
Table: Group
GroupId Name
11 Group 1
12 Group 2
Table: UserGroupMap
Id UserId CompanyCode GroupId
1 1 1234 11
2 1 1234 12
3 1 5678 11
4 2 1234 12
Here is my attempt to convert this use case into DGraph schema
type User {
name
companyCode
userGroups
}
type Group {
name
}
name: string @index(hash) .
companyCode: string @index(hash) .
userGroups: [uid] @reverse .
But with this approach I can able to maintain uniqueness of User + Company + Groups, but now I am duplicating user information for there each company.
How can I transform this into DGraph schema?
Any thoughts?