key_columns => { dunning_config_id => 'id' },
},
- fee_interest_ar => {
+ fee_interest_invoice => {
class => 'SL::DB::Invoice',
key_columns => { fee_interest_ar_id => 'id' },
},
+
+ invoice => {
+ class => 'SL::DB::Invoice',
+ key_columns => { trans_id => 'id' },
+ },
);
1;
assembly => { parts_id => 'part', id => 'assembly_part' },
assortment_items => { parts_id => 'part' },
+
+ dunning => { trans_id => 'invoice', fee_interest_ar_id => 'fee_interest_invoice' },
},
);
--- /dev/null
+-- @tag: dunning_foreign_key_for_trans_id
+-- @description: Mahnungstabelle: Fremdschlüssel für Verknüpfung zur Rechnungstabelle
+-- @depends: release_3_5_3
+DELETE FROM dunning
+WHERE NOT EXISTS (
+ SELECT ar.id
+ FROM ar
+ WHERE ar.id = dunning.trans_id
+);
+
+ALTER TABLE dunning
+ADD CONSTRAINT dunning_trans_id_fkey
+FOREIGN KEY (trans_id) REFERENCES ar (id)
+ON DELETE CASCADE;