سؤال

I want to delete all records from my tables using CakePHP syntax, how can I ?

I tried, deleteAll but it works with conditions only, the same way for delete, Is there any other way, I can empty my tables?

Let me know !

هل كانت مفيدة؟

المحلول

http://book.cakephp.org/2.0/en/models/deleting-data.html

I haven't used deleteAll() to delete an entire table, so I don't know whether you can call it without arguments (edit: you can't call it without arguments). However, you could just use

$this->Model->deleteAll(array('1 = 1'));

However, I think it would be better if you just ran the TRUNCATE SQL command via the query() method.

$this->Model->query('TRUNCATE table;');

نصائح أخرى

try to set $cascade true in your action as a second parameter , then all records are deleted if dependent is set to true in your model

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top