⚠ 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

DELETE rows from two dependent tables



putoyair
  • profile picture
  • Member

Posted 26 March 2013 - 05:46 AM

I am attempting to delete a row in two dependent tables based on a third tables ID.

Table structure:

 

Transaction
-Transaction_ID (primary)
-Timestamp

Purchase
-Item_ID
-Transaction_ID
-Purchase_ID (primary)

Item
-Item_ID (primary)
-Client_ID
 

 

The fact is that I Can't delete from a table as long as dependent records still exist in another table. so as the dependency goes like this

 

 

 

Transaction <- Purchase -> Item
 

How can I delete any purchases first before I can delete transactions. if I want to delete a Transaction in flexigrid?

or

How can I delete any Item first before I can delete transactions. if I want to delete an Item in flexigrid?

 

 I would also like ( if I try to delete either of them) to show a message and tell that there is a relation Purchase that have to be deleted before deleting either Transaction or Item?

 

 

 

Is a call_back the way to go or how=?


victor
  • profile picture
  • Member

Posted 26 March 2013 - 07:27 AM

use callback functions for that

davidoster
  • profile picture
  • Member

Posted 26 March 2013 - 07:30 AM

The exact same question was asked here:

http://stackoverflow.com/questions/2014257/mysql-delete-rows-from-two-dependent-tables

 

When you decide how you will proceed with your database then you have a few choices within Grocery CRUD.

1. extend the Grocery CRUD model and define your own delete function

2. unset_delete and add_action in order to provide your own delete action via a callback function

3. use your own model and callback_delete function to generate the desired result

 

2 and 3 can be pretty similar if 2 ends up using your own custom model!

 

The choice is yours.


davidoster
  • profile picture
  • Member

Posted 26 March 2013 - 07:31 AM

use callback functions for that

 

 

Hahahaha! Morning [member=victor]!!!


victor
  • profile picture
  • Member

Posted 26 March 2013 - 07:51 AM

you are right. I'm typing the message from my bed :-D