Jump to content

via Ad Packs

when I delete a record, which has a relationship ?

relation n_n delete

  • Please log in to reply
2 replies to this topic

#1 Lucas

Lucas

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

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

#2 noskov

noskov

    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

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.

#3 fdias

fdias

    grocery CRUD Addict

  • Members
  • PipPipPip
  • 87 posts

Posted 11 July 2012 - 05: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...ascade-in-mysql

Hope this helps





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users