The CollectionLoader should be used instead of the model factory to benefit from the dynamic type field feature to load the Attachment ID's sub-model.
|
$attachment = $this->modelFactory()->create(Attachment::class)->load($attachmentId); |
|
$attachment = $this->modelFactory()->create($attachment['type'])->setData($attachment->data()); |
|
|
|
if ($attachment['id'] !== null) { |
|
$attachment->delete(); |
|
} |