From 9ee5d635fc52f056cdbdd950c87e41b468e4899a Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Mon, 19 Jul 2021 16:19:52 +1000 Subject: [PATCH] chore: fix dynamodb parent collection handling. --- pkg/plugins/document/dynamodb/dynamodb.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/plugins/document/dynamodb/dynamodb.go b/pkg/plugins/document/dynamodb/dynamodb.go index 70f425fe3..25375d44e 100644 --- a/pkg/plugins/document/dynamodb/dynamodb.go +++ b/pkg/plugins/document/dynamodb/dynamodb.go @@ -430,15 +430,27 @@ func marshalQueryResult( for _, m := range valueMaps { // Retrieve the original ID on the result var id string + var c *sdk.Collection if collection.Parent == nil { // We know this is a root document so its key will be located in PK pk, _ := m[ATTRIB_PK].(string) id = pk + c = collection } else { // We know this is a child document so its key will be located in the SK + pk, _ := m[ATTRIB_PK].(string) sk, _ := m[ATTRIB_SK].(string) idStr := strings.Split(sk, "#") id = idStr[len(idStr)-1] + c = &sdk.Collection{ + Name: collection.Name, + Parent: &sdk.Key{ + Collection: &sdk.Collection{ + Name: collection.Parent.Collection.Name, + }, + Id: pk, + }, + } } // Get the sort key as a string @@ -448,7 +460,7 @@ func marshalQueryResult( sdkDoc := sdk.Document{ Key: &sdk.Key{ - Collection: collection, + Collection: c, Id: id, }, Content: m,