How come we need to disable the SoftDeletingScope::class on the resource but not on relation manager

I'm starting to implement soft deletes across my models and while the documentation says we need to add ->withoutGlobalScope(SoftDeletingScope::class) to the resource, why then do I not need to add this to the relation manager class via the ->modifyQueryUsing() method?
Solution:
It does but the it won't show deleted records without adjusting the query because the softdeletes always applies it without removing it
Jump to solution
5 Replies
Matthew
Matthew7d ago
You only want to do that if you want to be able to access soft-deleted records?
morty
mortyOP7d ago
It seems you can already access soft deletes on the relation manager without it though
toeknee
toeknee7d ago
@morty check the queries? We shouldn't be auto applying to a relationship because we wouldn't know if that relationship has soft deletes
morty
mortyOP6d ago
This is the query without removing the soft delete scope AND no trashed filter on the table:
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
AND [maintenance].[work_orders].[deleted_at] IS NULL
ORDER BY
[work_orders].[id] DESC;
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
AND [maintenance].[work_orders].[deleted_at] IS NULL
ORDER BY
[work_orders].[id] DESC;
This is the query when just adding the trashed filter only:
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
AND ([maintenance].[work_orders].[deleted_at] IS NULL)
ORDER BY
[work_orders].[id] DESC;
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
AND ([maintenance].[work_orders].[deleted_at] IS NULL)
ORDER BY
[work_orders].[id] DESC;
This is the query with again only adding the trashed filter but selecting either with deleted or only deleted:
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
ORDER BY
[work_orders].[id] DESC;
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
ORDER BY
[work_orders].[id] DESC;
And finally, this is the query after adding the withoutGlobalScope() and also still using the trashed filter:
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
AND ([maintenance].[work_orders].[deleted_at] IS NULL)
ORDER BY
[work_orders].[id] DESC
SELECT
TOP 10 *
FROM
[maintenance].[work_orders]
WHERE
[maintenance].[work_orders].[equipment_id] = 692
AND [maintenance].[work_orders].[equipment_id] IS NOT NULL
AND ([maintenance].[work_orders].[deleted_at] IS NULL)
ORDER BY
[work_orders].[id] DESC
So it would seem to me that just adding the trashed filter does the same thing? Regardless, the documentation says to remove the global scope so I will be doing that but I was just curious why it was still working.
Solution
toeknee
toeknee6d ago
It does but the it won't show deleted records without adjusting the query because the softdeletes always applies it without removing it

Did you find this page helpful?