Laravel\Nova\Fields\HasOne constructor does not exclude global scopes #6213
Unanswered
fjcantais
asked this question in
Ideas & Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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); }publishedboolean attribute, say "Customer"published=false.Beta Was this translation helpful? Give feedback.
All reactions