Modelling many-to-many relationship with Amplify and DynamoDB (adjacency list pattern)

Viewed 22

Context/use case

I'm trying to implement the following use case, and in order to model the many-to-many relationship I'm truing to use the Adjacency list pattern instead of the @manyToMany tags.

As a user I:
 - own multiple Items
 - I can organize my Items into Lists. One list can contain 0 or more items
 - An Item can be present in 1 or more lists of mine

Problem

With the adjacency list pattern I'm going to have just one table, and its row will be like:

PK SK Attrs
List-1 List-1 { name: "list 1", visibility: "visible", etc...}
List-1 Item-1 {...} this represents the item within a list
List-1 Item-2 {...} this represents the item within a list
Item-1 Item-1 specific attributes of the item (just the item!)
Item-2 Item-2 specific attributes of the item (just the item!)

Questions

  1. Does my example above makes sense or have I misunderstood the adjacency list pattern?
  2. How do I query all items for list 1 in one query?

I mean, if I just query list all items where PK is List-1 and SK begins with Item- I'll just get the ID pairs, but I won't get the specific attributes of each items (last two rows in the example above), so I'll also have to query every single item, which I want to avoid.

0 Answers
Related