1
class Model extends AppModel{

  public function deleteSomething(){

    if (empty($this->id)) {
      return false;
    }

    $this->read();

    $db =& ConnectionManager::getDataSource($this->useDbConfig);

    $db->begin($this);

    if (! $this->delete($this->id, true)) {
      $db->rollback($this);
      return false;
   }
   return $db->commit($this);
}

For some reason this will not delete?? I have debugged the id and it is correct. Any ideas? Am I missing something? }

2
  • 1
    Maybe you have some foreign key that prevents the deletion? Did you try to delete it manually? Commented Sep 12, 2013 at 10:29
  • Hi, do you mean manually as in running an SQL script directly on the table? If this is the case, then yes I have and it worked fine. Commented Sep 12, 2013 at 10:31

2 Answers 2

2

I can't see any commit function. I think it should be:

if (! $this->delete($this->id, true)) {
    $db->rollback($this);
    return false;
}
$db->commit($this);  
return true;
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry I did have one there, just missed it off when I copied it. I have edited it into the question now. Sorry
Tried your code in my app, everything works fine. You need to check problems in other place.
I have debugged the delete() and it says it ran successfully, with the right id. Then I debugged the commit and it returns true. But I go into the DB and the row is still there??
0
public function delete()
    {
        $this->layout = 'iphone_gps';
        $this->set('title_for_layout','Iphone GPS, LLC : Companies');
        $this->Companies = $this->request->data;
        if ($this->request->is('get')) {
            throw new MethodNotAllowedException();
        }
        foreach($this->Companies as $ids){
            $this->Companie->deleteAll(array('Companie.company_id' => $ids));
        }
        $this->Session->setFlash($this->deleted);
        $this->redirect('index');
    }

make one delete function in controller ... then next in index.ctp page

echo "<br>".$this->Form->input('Delete',array('class' => 'youreclass','style' => 'display:block;width:100px;','onclick'=>"return confirm('Are you sure for delete data?')",array('type'=>'hidden')));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.