October CMS resources and help articles

Simple and to the point. Optimized by the community.

Render Relation List/Form with trashed datas

2
by Slevin, last modified on November 20th, 2021

Sometimes, you have a model with related datas but those datas have softDelete enabled. And when you try to access the parent model, you may encounter an error due to some partials in your model form or list.

To avoid getting this error, you need to configure your relation to get the data with trashed.

Go to your parent model, and change your relation like this :

    public $belongsTo = [
        'relationName' => [ 
                    \Author\Plugin\Models\YourRelationModel::class,
                    'scope'=>'withTrashed'
                ],
    ];

and all works again.

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?