top-think / top-think/think-orm

升级后查询范围置后了,如果之前没写闭包的or查询会出现问题

Open
#648 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

升级后查询范围置后了,会之前没写闭包的or查询出现问题
比如:
User::scope('zuhu')->whereOr([['name','like','%'.$keyword.'%'],['email','like','%'.$keyword.'%'],['mobile','like','%'.$keyword.'%']])->select();
最终的语句是
SELECT * FROM user WHERE ( name LIKE '%12345678901%' OR email LIKE '%12345678901%' OR mobile LIKE '%12345678901%' AND zuhu_id = '1' ),
以前的语句是
SELECT * FROM user WHERE zuhu_id = '1' AND ( name LIKE '%12345678901%' OR email LIKE '%12345678901%' OR mobile LIKE '%12345678901%')

为啥要把scope条件置后呢?

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 ORM query-building path used by scope('zuhu'), whereOr(), and select(), then reproduce the two SQL forms shown in the issue. Trace why the scope predicate is placed inside the OR expression after the upgrade. Done means the scope condition is grouped with the intended precedence and the reported query produces the expected SQL; no files or tests are named.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.