Add function truncate to \Phalcon\Mvc\Model

Hi. Excuse me my missknowledge of phalcon, if i am wrong and show me the right way to truncate table.

Now im doing this:

class CurrencyCourse extends \Phalcon\Mvc\Model {

/**
 *
 * @var integer
 */
public $FROM_ID;

/**
 * Independent Column Mapping.
 */
public function columnMap()
{
    return array(
        'FROM_ID' => 'FROM_ID', 
    );
}

/**
 * Clear all table
 */
public function truncate() {
    $this->getDi()->getShared('db')->query("truncate table ".$this->getSource());
}
#or this 
    /**
 * Clear all table
 */
public function truncate() {
    // Instantiate the Query
    (new \Phalcon\Mvc\Model\Query("truncate table ".$this->getSource(), $this->getDI()))->execute();
}

} But i think it should be less level (C compiled).



34.6k

Hey

This you mean compile source ?

Models and model resultsets have a built-in delete() method. You can use it like so:

$Courses = CurrencyCourse::find();
$Courses->delete();

That will delete all the rows in the table. I haven't done query logging to see if it does a TRUNCATE query, 1 large DELETE query, or a bunch if individual DELETE queries.



1.4k

pretty sure that would result in a whole shit ton of individual delete queries :d



1.2k

Yeah, i think it would bi mass DELETE WHERE queries.

This you mean compile source ?

I mean native method of Mvc\Model (written to phalcon C-extension)