Welcome Guest, Not a member yet? Register   Sign In
Cannot get $useSoftDelete working
#1

I cannot make the 'Soft Delete' feature working in Codeigniter 4.1.1.

I setup the migration, model, and controller according to the documentation.

But the row is removed instead of marked delete date at 'deleted_at' column.

Wonder what I have missed to make it work as expected.

Migration
PHP Code:
$this->forge->addField("`deleted_at` datetime NULL"); 

Model

PHP Code:
class TestModel extends Model
{
    
// protected $DBGroup              = 'default';
    
protected $table                'test';
    protected 
$primaryKey           'id';
    
// protected $useAutoIncrement     = true;
    // protected $insertID             = 0;
    // protected $returnType           = 'array';
    
protected $useSoftDelete        true;
    
// protected $protectFields        = true;
    
protected $allowedFields        = ['district','state','country'];

    
// Dates
    
protected $useTimestamps        true;
    protected 
$dateFormat           'datetime';
    protected 
$createdField         'created_at';
    protected 
$updatedField         'updated_at';
    protected 
$deletedField         'deleted_at';



Controller

PHP Code:
$this->model model('App\Models\TestModel');
$this->model->delete(5); 
Reply
#2

Dear moderators,

I have found the cause of this problem, which is due to a typo in the spark command template for model.
It has already been fixed 6days ago, as shown in the Github repo:
https://github.com/codeigniter4/CodeIgni...1a819c92c2
Reply




Theme © iAndrew 2016 - Forum software by © MyBB