fix: columna FK incorrecta en contrato_servidores y filtrado de BDs en modal
- syncContratoJoin derivaba "contrato_servidore_id" en vez de "servidor_id" al recortar el último carácter del nombre de tabla; ahora usa TrimPrefix+TrimSuffix para derivar correctamente servidor_id, conx_db_id, ai_config_id - Modal contratos: filteredConxDbList filtra BDs por servidor(es) seleccionado(s) en vez de mostrar todas las BDs sin contexto Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
62397f2f8c
commit
dfe8d9e4a9
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
@@ -155,8 +156,11 @@ func syncContratoJoin(db *gorm.DB, table string, contratoID uint, ids []uint) er
|
||||
if err := db.Exec("DELETE FROM "+table+" WHERE contrato_id = ?", contratoID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// Derive FK column: "contrato_servidores" → "servidor_id", "contrato_conx_dbs" → "conx_db_id"
|
||||
entityPlural := strings.TrimPrefix(table, "contrato_")
|
||||
fkCol := strings.TrimSuffix(entityPlural, "s") + "_id"
|
||||
for _, id := range ids {
|
||||
if err := db.Exec("INSERT INTO "+table+" (contrato_id, "+table[:len(table)-1]+"_id) VALUES (?, ?) ON CONFLICT DO NOTHING",
|
||||
if err := db.Exec("INSERT INTO "+table+" (contrato_id, "+fkCol+") VALUES (?, ?) ON CONFLICT DO NOTHING",
|
||||
contratoID, id,
|
||||
).Error; err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user