mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-06-10 07:43:46 +00:00
fix(reflection): enhance GetForeignKeyColumn logic for self-referential models
* Add support for self-referential models in GetForeignKeyColumn * Update comments for clarity on foreign key resolution strategies * Introduce selfRefItem struct for testing self-referential behavior
This commit is contained in:
@@ -234,6 +234,8 @@ func (p *NestedCUDProcessor) injectForeignKeys(data map[string]interface{}, mode
|
||||
return
|
||||
}
|
||||
|
||||
pkCol := reflection.GetPrimaryKeyName(reflect.New(modelType).Interface())
|
||||
|
||||
for parentKey, parentID := range parentIDs {
|
||||
dbColNames := reflection.GetForeignKeyColumn(modelType, parentKey)
|
||||
|
||||
@@ -255,6 +257,9 @@ func (p *NestedCUDProcessor) injectForeignKeys(data map[string]interface{}, mode
|
||||
}
|
||||
|
||||
for _, dbColName := range dbColNames {
|
||||
if pkCol != "" && strings.EqualFold(dbColName, pkCol) {
|
||||
continue
|
||||
}
|
||||
if _, exists := data[dbColName]; !exists {
|
||||
logger.Debug("Injecting foreign key: %s = %v", dbColName, parentID)
|
||||
data[dbColName] = parentID
|
||||
|
||||
Reference in New Issue
Block a user