⚠ 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

Record id for custom delete



elfuego1
  • profile picture
  • Member

Posted 18 February 2013 - 11:39 AM

Hello,

 

Just before I delete a record from one table I need to look up, if there is a corresponding record in another table.

If there is, then delete from main table should be impossible.

 

I wonder if I should use callback_before_delete or just callback_delete?

I walnted to use callback_delete but I don't know how to acquire record id from main table for delete purposes.


victor
  • profile picture
  • Member

Posted 18 February 2013 - 12:08 PM

 $crud->callback_delete(array($this,'delete_user'));

public function delete_user($primary_key)
{
   Data from main table =     Select from main table where id = $primary_key

   Data from second table = Select * from second table where second table data =  Data from main table

   if(!empty(Data from second table)) return false;

else
  
  delete  from main table where id = $primary_key
   return true;

}

 

Try that way


victor
  • profile picture
  • Member

Posted 18 February 2013 - 12:12 PM

Or explain what do u want in more detail


elfuego1
  • profile picture
  • Member

Posted 18 February 2013 - 18:23 PM

That explanation SOLVED my problem!

callback_delete works like a charm now :)

 

Thank YOU very much Victor!!!