top-think / top-think/think-orm
hasWhere查询bug
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
重现代码
PayProviderGatewayModel::hasWhere('provider', ['status' => 1])
->hasWhere('account', ['status' => 1])
->hasWhere('channel', ['status' => 1])
->whereIn('gateway_group_id', $gateway_group_id)
->where('status', 1)
->where('channel_id', $this->order['channel_id'])
->select();
生成的sql语句是
SELECT
PayProviderGatewayModel.* FROMpay_provider_gatewayPayProviderGatewayModelINNER JOINpay_providerPayProviderModelONPayProviderGatewayModel.provider_id=PayProviderModel.provider_idINNER JOINpay_provider_accountPayProviderAccountModelONPayProviderGatewayModel.provider_account_id=PayProviderAccountModel.provider_account_idINNER JOINpay_channelPayChannelModelONPayProviderGatewayModel.channel_id=PayChannelModel.channel_idWHEREPayProviderModel.status= 1 ANDPayProviderAccountModel.status= 1 ANDPayChannelModel.status= 1 ANDgateway_group_id= 1 ANDstatus= 1 ANDchannel_id= 3
症状描述
pay_provider_gateway表的status字段查询是需要自动加上alias PayProviderGatewayModel的,但是并没有加,导致了报错。
最后我在代码中新增了
,解决了这个问题
另一个bug
另外hasWhere如果不放在第一个条件,也会报错,会导致主表pay_provider_gateway没有起别名
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the hasWhere query-generation entry point and reproduce the chained PayProviderGatewayModel query from the issue. Trace alias handling for the pay_provider_gateway status condition and for calls where hasWhere is not first; done means the generated SQL qualifies the main-table fields and preserves the main-table alias without errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100