top-think / top-think/think-orm
一对多withField无效
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
public function files()
{
return $this->belongsToMany(Fileinfo::class, RoomFile::class, 'fileid', 'serial');
}
$query->field('serial,roomname,starttime,endtime')
->with([
'files' => function (\think\model\Relation $query) {
$query->withField(['fileid','filename']);
}
])
依然还是查询了所有字段
SELECT
fileinfo.*,pivot.serialASpivot__serial,pivot.fileidASpivot__fileid,pivot.shownameASpivot__showname,pivot.typeASpivot__type,pivot.addtimeASpivot__addtime,pivot.suffixASpivot__suffix,pivot.sortASpivot__sort,pivot.warmvideoASpivot__warmvideoFROMfileinfoINNER JOINroomfilepivotONpivot.fileid=fileinfo.fileidWHERE (fileinfo.companyid= 1001219 ANDpivot.serial= '21431077062245' ) ANDfileinfo.deletetime= 0
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 with the belongsToMany relation and the withField call shown in the issue, then reproduce the generated SQL for the files relation. Trace how the requested fileid and filename fields are applied and verify that the query no longer selects every fileinfo and pivot column.
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
- 48/100