'Many to Many in DynamoDB requires additional queries

After reading a lot about how to handle many to many relationships in DynamoDB, I've come to the following solution.

Let's say a User has many Projects, and a Project can have many Users.

I've created a single table design with the following attributes:

PK --------- SK --------- entityType --------- name --------- GSI1--------- 
user_1       user_1       User                 Foo       
user_2       user_2       User                 Bar       
project_1    project_1    Project              My Project
project_1    pm_1         ProjectMember                       user_1  
project_1    pm_2         ProjectMember                       user_2

I can get the user's projects by using the GSI, and the project's users by using the PK and SK starts with pm_.

But when I get the project's users I get the ids. Now I need to get the whole information about each user.

Does running a batch get is the best practice here? I don't want to copy the user details to each pm row.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source