⚠ 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

as I can update a table after deleting a record in another?



Juan Carlos
  • profile picture
  • Member

Posted 29 October 2014 - 16:33 PM

Attached is a reference image, and actually think and apply it to multiple tables in different ways. 
 
Perhaps the solution could be using triggers, but I wonder if there is any way to do this using grocery crud, or otherwise appreciate the support of any member with the code of the trigger in mysql 
 
According to the attached image, I have two tables (project and client) 
 
First record of customers, so when I record the projects listed clients using set_relation.
 
Example, I have proposed the following records: 
 
Table Project: 
'proj001' 'project one', '02/01/2014', '29/10/2014', 'active', '1' 
 
Table Client: 
'1', 'one client', 'lima peru', '994584124', '1164661545' 
'2', 'client two', 'Caracas Venezuela', '154584124', '6498478965245' 
'3', 'client tree', 'santiago chile', '9545584124', '1654956245' 
 
So my first project log I linked to the first client (id_client = 1) when I delete the client "one client" my client crud value project.id_client already registered will remain "1" 
 
Eh researched and apparently can use the callback, but in your examples are always based on the same table, but not in two separate tables, not if someone can help me with a fully explicit example.

 

 


Amit Shah
  • profile picture
  • Member

Posted 30 October 2014 - 06:41 AM

well writing a fully explicit exmple is going to be tough time...!! but yes callback is the solution. I will recommend u do a callback before delete

where u pick the client id and make a call to a function in model which deletes the associated projects for the client. Its not that tough to write / execute around. !!