framework icon indicating copy to clipboard operation
framework copied to clipboard

Thinkphp6 批量删除恢复问题

Open gyjcode opened this issue 2 years ago • 7 comments

手册中没有实现批量删除恢复的示例,使用: $newCustomers = CustomerModel::select($ids); $newCustomers->restore(); 报错: Call to undefined method think\model\Collection::restore()

使用 saveAll 更新 delete_time 为 null 无效。估计是框架过滤了。

gyjcode avatar Aug 31 '22 00:08 gyjcode

无法直接更新 delete_time 吗?必须使用 restore() 更新 delete_time ?

gyjcode avatar Aug 31 '22 05:08 gyjcode

无法直接更新 delete_time 吗?必须使用 restore() 更新 delete_time ?

使用 force() 强制更新也不行

gyjcode avatar Aug 31 '22 05:08 gyjcode

看下我使用的

$data = model::onlyTrashed()->whereIn('id', $ids)->select();
                    foreach ($data as $k) {
                        $k->restore();
                    }

yuanzhihai avatar Aug 31 '22 05:08 yuanzhihai

看下我使用的

$data = model::onlyTrashed()->whereIn('id', $ids)->select();
                    foreach ($data as $k) {
                        $k->restore();
                    }

对,就是需要使用 restore 恢复软删除的,使用更新直接更新 delete_time 为 null 好像不管用。

gyjcode avatar Aug 31 '22 05:08 gyjcode

不知道你在纠结啥

yuanzhihai avatar Aug 31 '22 05:08 yuanzhihai

不知道你在纠结啥

倒不是纠结,早晨没更新成功,下午发现是这个的原因。因为恢复时还要修改其他内容,感觉不能一次性更新完成影响效率。

gyjcode avatar Aug 31 '22 07:08 gyjcode

你也可以在update前加上withTrashed,总之要明确当前代码操作的包不包含软删除。

augushong avatar Aug 31 '22 07:08 augushong