This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Laravel\Nova\Fields\HasOne constructor does not exclude global scopes #5955
Labels
pending
Issues that are pending triage
Description:
Laravel\Nova\Fields\HasOne constructor does not exclude global scopes. Therefore, if a global scope excludes a certain model instance from the query, it is impossible to assign a HasOne relationship. Nova throws an 'Attempt to read "[relationship_here]" on null'.
Current HasOne code:
$parent = $parentResource::newModel() ->with($this->attribute) ->find($request->viaResourceId);
Suggested correction:
$parent = $parentResource::newModel() ->withoutGlobalScopes() ->with($this->attribute) ->find($request->viaResourceId);
Detailed steps to reproduce the issue on a fresh Nova installation:
public function apply(Builder $builder, Model $model) { $builder->where('published', true); }
published
boolean attribute, say "Customer"published=false
.The text was updated successfully, but these errors were encountered: