php - Laravel Eloquent and Query Builder "with (nolock)" -
i have throuble because queries not have with (nolock)
instruction after from
clause.
because that, queries lock database , nobody can use system.
how use with (nolock)
eloquent & query builder?
for example.. in query:
return static::with('campaigntype') ->where('active', 1) ->get();
i want follow result:
select * campaigns (nolock) inner join campaign_types (nolock) on campaign_types.id = campaigns.campaign_type_id campaigns.active = 1
here how deal eloquent (tested on laravel 5.1 , 5.2)
you need add scope in model:
public function scopenolock($query) { return $query->from(db::raw(self::gettable() . ' (nolock)')); }
then can call like
return model::nolock()->get();