Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xyc92 opened this issue Jan 3, 2024 · 1 comment
Open
Labels

Comments

@xyc92
Copy link

xyc92 commented Jan 3, 2024

在全局定义了查询范围
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

请问有解决办法吗

@big-dream big-dream added the ORM label Mar 6, 2024
@ZoftTy
Copy link

ZoftTy commented Apr 22, 2024

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

修改成这样看看行不行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants