->onlyDeleted() returns all |
Hello,
I would like to use the softDelete Function from the CI Model Class. If I call the class with PHP Code: ->where(xyz)->delete() In my database the datetime will be written to "deleted_at". But as i started to implement a recycle bin to my application i want to get all items which are not null in deleted_at. CI Documentation says: PHP Code: $modelclass->onlyDeleted()->findAll(); But this return all entries also the not deleted... ![]() I build a function on my own to get just deleted items. It looks like this and it is also working but i think this is not the right way.. PHP Code: $deletedPersons = array(); Does anyone have experience with soft deletes in CI4 ? Maybe I used it the wrong way? best regards, Niklas
Can you confirm there are rows with the deleted_at field with a NULL value? Maybe your previous delete() really deleted all the rows.
(03-22-2020, 08:08 AM)includebeer Wrote: Can you confirm there are rows with the deleted_at field with a NULL value? Maybe your previous delete() really deleted all the rows. Yes i can confirm that the "deleted_at" rows have values so they are soft deleted and other rows have null. Both are returned by ->onlyDeleted(). Maybe there is a problem with mySql field settings. If the datetime field is null there is a "0000-00-00 00:00" in it. I don't know how CodeIgniter checks that field.
(03-25-2020, 03:58 AM)niklas Wrote:(03-22-2020, 08:08 AM)includebeer Wrote: Can you confirm there are rows with the deleted_at field with a NULL value? Maybe your previous delete() really deleted all the rows. If there is a value of “0000-00-00 00:00”, then it is not NULL. Is the deleted_at column nullable in your MySQL table? Maybe it have a default value of “0000-00-00 00:00”?
Oh my god.. I think i should not develop in the morning before 2 cups of coffee to activate my brain.
The deleted_at row was not nullable so 0000-00-00 00:00 is default value of mySql. I change it to nullable and set defaultvalue to null and oh... it work's. Thank you very much!!
|
Welcome Guest, Not a member yet? Register Sign In |