Skip to content

Commit

Permalink
Fix parent child listing. Closes #378
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Aug 10, 2022
1 parent de3cb13 commit 41242df
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions plugin/query_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,20 @@ func (d *QueryData) streamListItem(ctx context.Context, items ...interface{}) {
return
}
// if this table has no parent hydrate function, just call streamLeafListItem directly
parentListHydrate := d.Table.List.ParentHydrate
if parentListHydrate != nil {
// so there is a parent hydrate - call it
d.callParentHydrate(ctx, parentListHydrate, item)
if d.Table.List.ParentHydrate != nil {
// so there is a parent-child hydrate - call the child hydrate, passing 'item' as the parent item
d.callChildListHydrate(ctx, item)
} else {
// otherwise call streamLeafListItem directly
d.streamLeafListItem(ctx, item)
}
}
}

func (d *QueryData) callParentHydrate(ctx context.Context, parentListHydrate HydrateFunc, item interface{}) {
// there is a parent-child list hydration - call the child list function passing 'item' as the parent item'
func (d *QueryData) callChildListHydrate(ctx context.Context, parentItem interface{}) {
// do a deep nil check on item - if nil, just return to skip this item
if helpers.IsNil(item) {
if helpers.IsNil(parentItem) {
return
}
callingFunction := helpers.GetCallingFunction(1)
Expand All @@ -436,9 +436,9 @@ func (d *QueryData) callParentHydrate(ctx context.Context, parentListHydrate Hyd
childQueryData := d.ShallowCopy()
childQueryData.StreamListItem = childQueryData.streamLeafListItem
// set parent list result so that it can be stored in rowdata hydrate results in streamLeafListItem
childQueryData.parentItem = item
childQueryData.parentItem = parentItem
// now call the parent list
_, err := parentListHydrate(ctx, childQueryData, &HydrateData{Item: item})
_, err := d.Table.List.Hydrate(ctx, childQueryData, &HydrateData{Item: parentItem})
if err != nil {
d.streamError(err)
}
Expand Down

0 comments on commit 41242df

Please sign in to comment.