Skip to content

Commit

Permalink
PLIN-5811-Fixed lookups by ForeignKey (#105)
Browse files Browse the repository at this point in the history
* PLIN-5811-Fixed lookups by ForeignKey

* PLIN-5811 - Cleanup warnings and fixed foreign lookup order

* Fix typo

* Keep existing logic for skipping foreign keys without lookup data

* Make foreignKeysToLookup more readable

---------

Co-authored-by: German Zapata <[email protected]>
Co-authored-by: German Zapata <[email protected]>
Co-authored-by: acofer <[email protected]>
  • Loading branch information
4 people authored Aug 21, 2024
1 parent c4eacf8 commit b977fe3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 77 deletions.
9 changes: 5 additions & 4 deletions picard.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func getLookupsForDeploy(data interface{}, tableMetadata *tags.TableMetadata, fo

// Create a new slice of all the foreign keys for this type
foreignKeysToCheck := tableMetadata.GetForeignKeys()[:]

foreignKeysToLookup := []tags.ForeignKey{}
hasValidPK := false
// Determine which lookups are necessary based on whether keys exist in the data
s := reflect.ValueOf(data)
Expand Down Expand Up @@ -613,8 +613,9 @@ func getLookupsForDeploy(data interface{}, tableMetadata *tags.TableMetadata, fo
})
} else {
// We don't have the id value for this foreign key so it does need a lookup
// But we should only pass on the ones where the original data has the values to lookup
if !hasForeignKeyData(item, foreignKeyToCheck) {
if hasForeignKeyData(item, foreignKeyToCheck) {
// Let's keep the order
foreignKeysToLookup = append([]tags.ForeignKey{foreignKeyToCheck}, foreignKeysToLookup...)
foreignKeysToCheck = append(foreignKeysToCheck[:i], foreignKeysToCheck[i+1:]...)
}
}
Expand All @@ -625,7 +626,7 @@ func getLookupsForDeploy(data interface{}, tableMetadata *tags.TableMetadata, fo
lookupsToUse = append(lookups, lookupsToUse...)
}

lookupsToUse = append(lookupsToUse, getLookupsFromForeignKeys(foreignKeysToCheck, "", "", tableAliasCache)...)
lookupsToUse = append(lookupsToUse, getLookupsFromForeignKeys(foreignKeysToLookup, "", "", tableAliasCache)...)

return lookupsToUse
}
Expand Down
Loading

0 comments on commit b977fe3

Please sign in to comment.