CodeIgniter-MY_Model
CodeIgniter-MY_Model copied to clipboard
The count_row function counts with deleted rows.
$this->soft_deletes = true;
This is not affect the count_row function.
Quick fix:
public function count_rows($where = NULL)`
{
if(isset($where))
{
$this->where($where);
}
/*add this*/
elseif($this->soft_deletes===TRUE)
{
$this->_where_trashed();
}
$this->_database->from($this->table);
$number_rows = $this->_database->count_all_results();
return $number_rows;
}
As the criteria to include or exclude trashed records is always evaluated it the where method. Make a call to the where method without any arguments and it will exclude the trashed records.
$count = $this->some_model->where()->count_rows();
//or if you have another where clause
$count = $this->some_model->where('some_field_name','value')->count_rows();
Both will exclude the trashed records.