Skip to content

Editing resource that has a HasOne self reference results in error #5432

@sedlatschek

Description

@sedlatschek

Description:

Hi,

I have a model called Deadline, which has two self-referencing relations called postponed and postpones:

class Deadline extends Model
{
    use HasFactory;

    protected $fillable = [
        'exceeds_at',
        'postponed_id',
    ];

    protected $casts = [
        'exceeds_at' => 'datetime',
    ];

    public function postponed(): BelongsTo
    {
        return $this->belongsTo(Deadline::class);
    }

    public function postpones(): HasOne
    {
        return $this->hasOne(Deadline::class, 'postponed_id');
    }
}

The nova resource for this model looks like this:

class Deadline extends Resource
{
    public static $model = \App\Models\Deadline::class;

    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable(),
            Date::make('exceeds_at'),
            BelongsTo::make('Postponed To', 'postponed', Deadline::class)
                ->readonly(),
            HasOne::make('Postponed From', 'postpones', Deadline::class)
                ->readonly(),
        ];
    }
}

I can view the resources without any problems:
image

But when I click on the edit button, I get endless loading:
image

The nova-api requests returns HTTP 500 after either running out of memory or hitting the maximum execution time.

The Update.vue then runs into the following error:

Update.vue:165 Uncaught (in promise) TypeError: Cannot destructure property 'data' of '(intermediate value)' as it is undefined.
    at Proxy.getFields (Update.vue:165:9)

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

  1. Clone https://github.com/sedlatschek/laravel-10-nova-4-issues
  2. php aritsan migrate:fresh -seed
  3. Open any Deadline resource
  4. Click on the edit button

Thanks for your help

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