think-orm
think-orm copied to clipboard
软删除查询拼接字段值错误
trafficstars
输出的SQL语句,delete_time 应该是个 int 才对,现在变成了 string,会导致索引问题
SELECT * FROM `admin` WHERE ( `id` = 1 ) AND `admin`.`delete_time` = '0' LIMIT 1
我的软删除模型定义
<?php
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @method $this fetchSql(bool $fetch = true) 获取查询语句,返回 string
* @method $this buildSql(bool $sub = true) 构建子查询语句,返回 string
**/
class BaseModel extends Model
{
// 引入软删除功能
use SoftDelete;
protected function init(): void
{
parent::init();
$this->setOptions([
'defaultSoftDelete' => 0,
]);
}
}