top-think / top-think/think-orm

软删除查询拼接字段值错误

Open
#720 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

输出的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,
        ]);
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the SoftDelete behavior and Model query construction using the BaseModel definition and generated SQL shown in the issue. Reproduce the query and verify that delete_time is emitted as the integer 0 rather than the string '0', then confirm the resulting SQL remains compatible with the intended index usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.