Laravel Eloquent 和查询生成器“with (nolock)”

Pat*_*iel 2 php sql sql-server laravel eloquent

我遇到了一些麻烦,因为我的查询在子句后没有with (nolock)说明from

因此,某些查询会锁定数据库,然后任何人都无法使用该系统。

如何使用with (nolock)Eloquent & Query Builder?

例如..在此查询中:

return static::with('campaignType')
    ->where('active', 1)
    ->get();
Run Code Online (Sandbox Code Playgroud)

我想要以下结果:

select
    *
from campaigns with (nolock)
inner join campaign_types with (nolock) on campaign_types.id = campaigns.campaign_type_id 
where campaigns.active = 1 
Run Code Online (Sandbox Code Playgroud)

Tol*_*ola 5

你可以像这样设置“with(nolock)”:

DB::table('campaigns')->lock('WITH(NOLOCK)')
Run Code Online (Sandbox Code Playgroud)