phpmysqlcakephpcakephp-2.3

CakePHP delete records older than 5 days


Basically, I want to do this in CakePHP:

delete from myTable as mytable where datediff(now(), mytable.date) > 5

And I don't know how to do it with the $this->Model->delete() function?


Solution

  • You need to use deleteAll:

    $this->Model->deleteAll(array(
        'datediff(now(), Model.date) > 5'
    )) ;