Deleting a record from lookup table

FRW

Well-known member
Just to understand, what I have to do:

From table "A" I have a single select with a lookup table "B". I want to prevent deleting the record in table "B" if there are records in table "A" who are linked to this entry. (f.e.: the master/detail view in table "B" is not empty).

Do I have to do this with before_delete_hook or any other simple prevention possible?
 

Martin68

Well-known member
Its a typical case of a foreign key constraint in the database !

Look here: https://www.w3schools.com/sql/sql_foreignkey.asp

Kind regards

Martin
 

FRW

Well-known member
Hi Martin,

thank you for your response.
Yes, I know foreign key for the DBMS, but this will lead to na error and won't lead to a clear message for the useres in dadabik, i think
 

eugenio

Administrator
Staff member
Hello,
if it doesn't happen frequently, maybe you can just set a constraint as Martin suggests, otherwise and if you want a custom message I would set the constraint + a before_delete hook

Best,
 
Top