Skip to content

Commit 64ad3a9

Browse files
committed
fix: chiavi esterne
1 parent 694fef8 commit 64ad3a9

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

modules/interventi/src/Intervento.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public static function build(Anagrafica $anagrafica, TipoSessione $tipo_sessione
7171
$model->idagente = $anagrafica->idagente;
7272
$model->idpagamento = setting('Tipo di pagamento predefinito');
7373

74+
// Set idclientefinale to the same as idanagrafica by default to avoid foreign key constraint violation
75+
$model->idclientefinale = $anagrafica->idanagrafica;
76+
7477
$user = \Auth::user();
7578
$id_sede = null;
7679
foreach ($user->sedi as $sede) {

update/2_9_2.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ ALTER TABLE `dt_righe_ddt` ADD CONSTRAINT `dt_righe_ddt_ibfk_3` FOREIGN KEY (`id
150150
ALTER TABLE `dt_righe_ddt` ADD CONSTRAINT `dt_righe_ddt_ibfk_4` FOREIGN KEY (`idiva`) REFERENCES `co_iva`(`id`) ON DELETE RESTRICT;
151151

152152
-- FOREIGN KEYS per tabelle interventi
153-
ALTER TABLE `in_interventi` ADD CONSTRAINT `in_interventi_ibfk_10` FOREIGN KEY (`idreferente`) REFERENCES `an_referenti`(`id`) ON DELETE RESTRICT;
153+
-- Prima modifichiamo il campo idreferente per permettere valori NULL
154+
ALTER TABLE `in_interventi` MODIFY `idreferente` int(11) NULL;
155+
-- Poi aggiungiamo il vincolo foreign key che permette valori NULL
156+
ALTER TABLE `in_interventi` ADD CONSTRAINT `in_interventi_ibfk_10` FOREIGN KEY (`idreferente`) REFERENCES `an_referenti`(`id`) ON DELETE SET NULL;
154157
ALTER TABLE `in_interventi` ADD CONSTRAINT `in_interventi_ibfk_11` FOREIGN KEY (`idclientefinale`) REFERENCES `an_anagrafiche`(`idanagrafica`) ON DELETE RESTRICT;
155158

156159
ALTER TABLE `in_righe_interventi` ADD CONSTRAINT `in_righe_interventi_ibfk_4` FOREIGN KEY (`idiva`) REFERENCES `co_iva`(`id`) ON DELETE RESTRICT;

0 commit comments

Comments
 (0)