Welcome Guest, Not a member yet? Register   Sign In
deleted_at not getting set
#1

Hello, 

I have codeigniter 4.18 installed and my model has the following settings
the database is postgresql 12
the fields in the database are timestamp without time zone data type
protected $table = 'news';
    protected $primaryKey = 'id';

    protected $useAutoIncrement = true;

    protected $returnType    = 'App\Entities\News\Article';
    protected $useSoftDeletes = true;

    protected $allowedFields = ['title', 'body','me_uid','record_status'];

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

    protected $validationRules    = [];
    protected $validationMessages = [];
    protected $skipValidation    = false;

    protected $record_status = 1;

I have the following method deleting a record in the model
$id = $record->id;
$this->delete($id);
according to the documentation the above code should update the deleted_at field with a timestamp and that is not happening
If I save / update a record the updated_at field gets set with the updated timestamp so that is working properly
when a record is saved the created_at field is getting set correctly
any advice or solution would be greatly appreciated
Reply
#2

When using soft delete, the delete method works like an update. And if the update works, then a soft delete will work.
There are two reasons why it won't work.
1. $id is empty;
2. $id is not in the database.
Reply
#3

Thank you for the update
I got it to work
I had a method named delete in the model class which was overriding the default delete method available in the model
I renamed the method to deleteRecord which then called the default delete method in the model and now deleted_at is getting set
Reply




Theme © iAndrew 2016 - Forum software by © MyBB