public function post_delete()Everythng work perfectly for attachments but when I call $conversation->delete(), this error is raised :
{
// POST data
$id = \Input::post('id');
$control = \CiData\Model\DeliberateControl::find($id);
if($control == null)
{
return $this->response('Control not found', 404);
}
// Delete all Conversation (messages, attachments)
$conversation = $control->wf_msg_conversations;
$attachments = $conversation->wf_msg_attachments;
foreach ($attachments as $i => $attachment)
{
// Delete file from server
\File::delete('modules/messages'.DS.$conversation->name.'_'.$conversation->id.DS.$attachment->name);
$attachment->delete();
}
$conversation->delete();
$control->delete();
return $this->response('SUCCESS');
}
protected static $_has_many = array(Attachment Model :
'wf_msg_messages' => array(
'model_to' => 'Messages\\Model\\Message',
'key_from' => 'id',
'key_to' => 'conversation_id'
),
'wf_msg_attachments' => array(
'model_to' => 'Messages\\Model\\Attachment',
'key_from' => 'id',
'key_to' => 'conversation_id'
)
);
protected static $_belongs_to = array(Ok I'm going to try to define cascade_delete to true and only delete files in foreach loop.
'wf_msg_conversations' => array(
'model_to' => 'Messages\\Model\\Conversation',
'key_from' => 'conversation_id',
'key_to' => 'id'
)
);
It looks like you're new here. If you want to get involved, click one of these buttons!