Skip to content

Commit

Permalink
chore: fix dynamodb parent collection handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Jul 19, 2021
1 parent 26b5401 commit 9ee5d63
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/plugins/document/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -448,7 +460,7 @@ func marshalQueryResult(

sdkDoc := sdk.Document{
Key: &sdk.Key{
Collection: collection,
Collection: c,
Id: id,
},
Content: m,
Expand Down

0 comments on commit 9ee5d63

Please sign in to comment.