title: Delete data that contains foreign key
body: <p>I usually work with foreign key for good practices and to maintain data integrity but I always face the following &quot;problem&quot; when trying to delete some data:</p>
  <p>I have a scenario with a main group table: <strong>groups</strong></p>
  <p>And I have several other tables that relate to groups, for example:</p>
  <p><strong>user_group (relationship table between users and groups)</strong></p>
  <p><strong>course_group (relationship table between courses and groups)</strong></p>
  <p>When deleting a group I always need to delete the reference to that group in the related tables before ... but currently I have several relationship tables and my exclusion code ends up getting quite large.</p>
  <blockquote>
  <p>My question is: is there any function or library that I could use so that this work could be done more automatically? A function that may check for me all these references and already exclude. If anyone has any idea how to make it faster and with the smallest possible number of code thanks. <strong>Note: I am currently working with PHP</strong></p>
  </blockquote>