From dfe8d9e4a9ae33e6ca5a220a4d34da06f42830f5 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 9 Jul 2026 11:58:01 -0500 Subject: [PATCH] fix: columna FK incorrecta en contrato_servidores y filtrado de BDs en modal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- pkg/models/contrato.go | 6 +++++- resources/views/renovaciones/contratos.html | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/models/contrato.go b/pkg/models/contrato.go index 9bf0d9b..bffbfe2 100644 --- a/pkg/models/contrato.go +++ b/pkg/models/contrato.go @@ -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 diff --git a/resources/views/renovaciones/contratos.html b/resources/views/renovaciones/contratos.html index a222270..84fa937 100644 --- a/resources/views/renovaciones/contratos.html +++ b/resources/views/renovaciones/contratos.html @@ -230,7 +230,7 @@
-