Askedio/laravel-soft-cascade

Should withTrashed scope be applied?

Closed this issue · 2 comments

In this example, i have both User and Profile models. User hasOne Profile. Both models are using soft deletes. Soft Cascade is configured on User model.

The package functionality is working as expected, but, i'm wondering if the following behavior should be expected:

$profiles = Profile::withTrashed()->get();

I can have all my profiles, including soft deleted ones with the query above, but it's not retrieving the related user, since it's soft deleted.

What do you think about it? Should this package be responsible to handle this and add the withTrashed scope on the related model as well?

Similar to this: https://stackoverflow.com/a/25875054/3948755

It's not a package or Laravel problem!
Yo should use load method after query or with before query. Example:

//Before query
$profiles = Profile::withTrashed()->with([
        'user' => function($query) {
            $query->withTrashed();
        }
    ])->get();

//After query
$profiles = Profile::withTrashed()->get();
$profiles->load([
        'user' => function($query) {
            $query->withTrashed();
        }
    ]);

Ok, thank you!