top-think / top-think/think-orm

WhereOr返回的过滤条件为什么是AND

Open
#770 14 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

WhereOr过滤条件大家都不使用吗?如下:
`
$where[] = ['mobile', 'like', 'thinkphp%'];
$whereOr[] = ['name', 'like', '%thinkphp'];
Db::name("abstract_logic_testing")->where($where)->whereOr($whereOr)->select();

$actual = Db::name("abstract_logic_testing")->getLastSql();
`

这段代码$actual的结果,不应该是SELECT * FROM m_abstract_logic_testing WHERE ( mobile LIKE 'thinkphp%' ) OR ( name LIKE '%thinkphp' )吗?为什么结果是 SELECT * FROM m_abstract_logic_testing WHERE ( mobile LIKE 'thinkphp%' ) AND ( name LIKE '%thinkphp' )。

这个问题从版本3.0.31就出现了(3.0.30运行这段代码符合预期:是用OR链接的两个条件),到现在4.x版本了都是错的(是用AND连接的两个条件)。

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 with the chained where() and whereOr() calls shown in the issue and inspect how getLastSql() builds the condition. Compare the behavior in version 3.0.30 with 3.0.31 and 4.x. Done means the example combines the mobile and name conditions with OR as expected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.