Skip to content

HasOne relationship shows trashed resources #4118

@Hannoma

Description

@Hannoma
  • Laravel Version: 8.83.9
  • Nova Version: 4.2.5
  • PHP Version: 8.1.3

Description:

In my user resource, there is a HasOne relationship to accesses. The accesses are using the soft-deleted trait. In Nova, the attached soft-deleted access is shown in the user detail page. In our case, this is not expected behavior and this behavior deviates from the HasOne relationship behavior of laravel/eloquent. Because in that case, soft-deleted models are not concerned. In addition, there is no method available like for the BelongsTo field to filter out trashed models.
image

Detailed steps to reproduce the issue on a fresh Nova installation:

Models/User.php

public function access(): HasOne
{
    return $this->hasOne(Access::class);
}

Nova/User.php

public function fields(NovaRequest $request): array
{
    // More fields here
    HasOne::make('Access')->exceptOnForms(),
}

Models/Access.php

public function user(): BelongsTo
{
    return $this->belongsTo(User::class)->withTrashed();
}

Nova/Access.php

public function fields(NovaRequest $request): array
{
    // More fields here
    BelongsTo::make('User')
                ->exceptOnForms(),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions