DeleteTrait
Delete operations.
Cache invalidation happens in the manager layer after commit (tag bump; bulk deleteAll()
and tree deletes bump explicitly, see the Managers DeleteTrait and TreeTrait). The
service only deletes through the mapper.
Tags
Table of Contents
Methods
- delete() : Result
- Delete entity by ID.
- deleteAll() : Result
- Delete multiple entities by IDs.
- deleteBy() : Result
- Delete entity by filters.
- find() : object|null
- deleteWithoutCache() : Result
- Delete entity from database via Mapper.
- getEntityClass() : class-string
- isTechnicalDeleteFailure() : bool
- Technical failure = the persistence layer broke (exception attached or a technical code); the EntityManager may be closed and no further write may be attempted.
Methods
delete()
Delete entity by ID.
public
delete(int|array<string|int, mixed> $id) : Result
IMPORTANT: an array means a list of ids, not a composite key (Mapper::find() takes
only int). Without this redirect to deleteAll() every bulk delete from the DataGrid
ends with TypeError: Mapper::find(): Argument #1 ($id) must be of type int, array given
(the grid calls Manager::delete($ids) with the array of selected rows).
Parameters
- $id : int|array<string|int, mixed>
-
Entity ID to delete
Return values
Result —Success if deleted, Error if entity not found
deleteAll()
Delete multiple entities by IDs.
public
deleteAll(array<string|int, mixed> $ids) : Result
Partial success is the contract for domain refusals (missing id, guard): the loop
continues and the errors are listed next to deletedCount. A technical failure
(DB_ERROR and similar, see ResultCode::isTechnical()) aborts the loop instead: after a
failed ORM flush Doctrine closes the EntityManager, so the next remove() would throw
EntityManagerClosed out of the loop and the caller would get no summary of the rows
already deleted (durable in autocommit). The failed Result carries deletedIds,
failedId and remainingIds; the caller decides whether the accepted prefix stays
(autocommit) or is rolled back (the manager bulk paths run inside a transaction and roll
it back).
Parameters
- $ids : array<string|int, mixed>
-
entity ids (int or numeric string); for a composite key an array
[property => value]
Return values
Result —Success with delete count, or Error
deleteBy()
Delete entity by filters.
public
deleteBy(array<string|int, mixed> $filters) : Result
Parameters
- $filters : array<string|int, mixed>
-
Filter conditions
Return values
Result —Success if deleted, Error if not found
find()
public
abstract find(int|array<string|int, mixed> $id[, string|array<string|int, mixed> $includes = [] ][, bool $useCache = true ]) : object|null
Parameters
- $id : int|array<string|int, mixed>
- $includes : string|array<string|int, mixed> = []
- $useCache : bool = true
Return values
object|nulldeleteWithoutCache()
Delete entity from database via Mapper.
protected
deleteWithoutCache(BaseEntity $entity) : Result
Called internally by delete() and deleteAll().
Parameters
- $entity : BaseEntity
Return values
ResultgetEntityClass()
protected
abstract getEntityClass() : class-string
Return values
class-stringisTechnicalDeleteFailure()
Technical failure = the persistence layer broke (exception attached or a technical code); the EntityManager may be closed and no further write may be attempted.
private
isTechnicalDeleteFailure(Result $result) : bool
Parameters
- $result : Result