What would be the best approach if I want to put validation upon record deletion? Here is the reason why.
I have two tables, Store and Staff.
Structure of Store:
Structure of Staff:
As you can see, table store is related to table staff.
What if the user tries to delete a store that is already used on table staff? If no validation, my data would be broken. How can I prevent it?
Thanks.
The best way to implement it is through the referential integrity in the database, not in framework.
Structure of STORE:
Structure of STAFF:
As you can see, the STAFF table "belongs" to STORE because it contains the ID of a parent record. This is a classical One-to-many association: http://javalite.io/one_to_many_associations
You can do one of two things:
A few links suggested by Google:
https://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html http://www.mysqltutorial.org/mysql-on-delete-cascade/