Reputation: 35
M new in cakephp. M using cakephp 2X. I have model Student and Document.
Student hasMany Document
Document belognsTo Student
I need to delete documents when i am delete student. That student's all documents also been delete.
Upvotes: 0
Views: 689
Reputation: 201
Try This :
In Model :
// In your Student Model
var $hasMany=array('Student'=>array('className'=>'Student',
'foreignKey'=>'student_id',
'dependent'=>true, // true without single quote
'exclusive'=>true
)
);
//In your Document Model
var $belongsTo = array('User'=>array('className'=>'Student',
'foreignKey'=>'student_id'
)
);
In Controller :
$this->Model->delete($item_to_delete_id,true);
Upvotes: 2