Welcome Guest, Not a member yet? Register   Sign In
Write this Query with Active Record?
#1

[eluser]seanloving[/eluser]
I figured out how to perform a multi-table delete in MySQL to remove a single contact record.

I wonder is there a way to write this query with AR?

Code:
function delete_contact( $id ) {
    
  /* Multi-Table Delete via MySQL
   Foreign Key References defined in the link tables are set to DELETE CASCADE
   To avoid FK REFs (e.g MyISAM) then just add the link table names to the DELETE statement
  */
  $this->db->query(" DELETE contacts, addresses, emailaddresses, numbers
       FROM contacts
        INNER JOIN addresses_contacts INNER JOIN addresses
        INNER JOIN contacts_emailaddresses INNER JOIN emailaddresses
        INNER JOIN contacts_numbers INNER JOIN numbers
       WHERE contacts.contact_id = $id
        AND addresses.address_id = addresses_contacts.address_id
        AND emailaddresses.emailaddress_id = contacts_emailaddresses.emailaddress_id
        AND numbers.number_id = contacts_numbers.number_id;
      ");
}






Theme © iAndrew 2016 - Forum software by © MyBB