mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 01:44:04 +00:00
Delete pivot records when deleting SyncMaster using morph pivot (#46)
* Add and correct pivot record tests * Implement and test deleting pivot records when using morph pivot * Use dataset to test deleting pivot records with both MorphTenantPivot and TenantPivot * Delete extra test, use createTenantsAndRunMigrations() where appropriate * FIx PHPStan errors * Revert DB::table() assertion changes * minor test improvements --------- Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
4e51cdbacb
commit
77226cf2f4
2 changed files with 55 additions and 15 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\ResourceSyncing\Listeners;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Stancl\Tenancy\Listeners\QueueableListener;
|
||||
use Stancl\Tenancy\ResourceSyncing\Events\SyncMasterDeleted;
|
||||
|
||||
|
|
@ -20,6 +21,12 @@ class DeleteResourcesInTenants extends QueueableListener
|
|||
|
||||
tenancy()->runForMultiple($centralResource->tenants()->cursor(), function () use ($centralResource, $forceDelete) {
|
||||
$this->deleteSyncedResource($centralResource, $forceDelete);
|
||||
|
||||
// Delete pivot records if the central resource doesn't use soft deletes
|
||||
// or the central resource was deleted using forceDelete()
|
||||
if ($forceDelete || ! in_array(SoftDeletes::class, class_uses_recursive($centralResource::class), true)) {
|
||||
$centralResource->tenants()->detach(tenant());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue