⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

when I delete a record, which has a relationship ?



Lucas
  • profile picture
  • Member

Posted 11 July 2012 - 01:13 AM

when I delete a record, which has a relationship, I want to take a message telling me that I can not remove

anyone know how to do

noskov.biz
  • profile picture
  • Member

Posted 11 July 2012 - 05:38 AM

Hi, Lucas!

Try to play with callback_before_delete function. It seems to me that is the easiest way.

fdias
  • profile picture
  • Member

Posted 11 July 2012 - 17:15 PM

Either use a callback_before_delete function as suggested by noskov or you can cascade delete the records if you are absolutely sure you won't need them.
For example you have a table of clients and a table of phone numbers related to clients. Whenever you delete a client you want to delete all phone numbers of that particular client. If this is your case then use cascade delete on your mysql, considering you are using InnoDB.

If you don't know how to use the on delete cascade, then check this post at stackoverflow:

http://stackoverflow.com/questions/511361/how-do-i-use-on-delete-cascade-in-mysql

Hope this helps