DELETE DATA FROM TWO TABLES LINK WITH EACH OTHERS IN CAKEPHP 3
Step : Go to your models which you want delete record from database and paste this code. <?php $this->hasMany('your_table_name', [ 'foreignKey' => 'your_id_name', 'dependent' => true, 'cascadeCallbacks' => true, ]); ?>
Share
Manish Garg
I think this code also use in the controller
Or simply if two tables were connected with each other then must be there one primary key and one foreign key in both table simply create a relation between two tables in sql if primary key data is deleted then foreign key data automatic delete itself 🙂
ak hil
or simply if we don’t want to do code we create a relationship between these two tables in database by doing this if primary key data is deleted then foreign key data automatic deleted 🙂