framework icon indicating copy to clipboard operation
framework copied to clipboard

多个模型定义全局查询范围的时候使用join会报错的问题

Open xyc92 opened this issue 1 year ago • 1 comments

在全局定义了查询范围 protected $globalScope = ['is_delete'];

public function scopeIs_Delete($query): void
{
    $query->where('is_delete',0);
}

正常使用Model::withoutGlobalScope()可以关闭这个范围

但是在闭包里面join查询时候没有办法调用这个静态方法,还是会报字段重复的错误 SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'is_delete' in where clause is ambiguous

请问有解决办法吗

xyc92 avatar Jan 03 '24 00:01 xyc92

public function scopeIs_Delete($query): void
{
    $query->where('__TABLE__.is_delete', 0);
}

修改成这样看看行不行。

ZoftTy avatar Apr 22 '24 01:04 ZoftTy