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:
Lizandro Guarnizo
2026-07-09 11:58:01 -05:00
co-authored by Claude Sonnet 4.6
parent 62397f2f8c
commit dfe8d9e4a9
2 changed files with 12 additions and 3 deletions
+5 -1
View File
@@ -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