withoutGlobalScopes 对多态关联中的内容不起作用
以文档一对多(多态)中的模型举个例子,posts、videos、comments三张表
在posts上增加个全局作用域
public function apply(Builder $builder, Model $model)
{
$builder->where('title', 'like','abc');
}
查询的时候无论我在with中增加withoutGlobalScopes,还是在关联关系定义的时候增加withoutGlobalScopes,都不能使这个作用全局域失效
app\comment::with(['commentable'=>function ($query) {
query->withoutGlobalScopes();
}])->get();
public function commentable()
{
return $this->morphTo()->withoutGlobalScopes();
}
只有在多态关联中不好使,其他关联关系我这么写都是可以的。
推荐文章: