# DeletedBy() function · @imqueue/pg-sequelize

Source: https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.deletedby/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-sequelize 4.2.0 — generated reference, not hand-written

Stamps the decorated column with the acting user id on soft-delete (and clears it on restore), taken from the in-flight IMQ request metadata (`currentMetadata()?.userId`). Mirrors `@DeletedAt`: set on delete, cleared on restore, and a delete touches neither `updatedAt` nor an `@UpdatedBy` column.

A property decorator for paranoid models, reusable on any field. Soft-delete runs through `Model.destroy`, which Sequelize turns into a `deletedAt`-only UPDATE whose value hash is built internally and is unreachable from any hook. So instead of mutating that statement, the `beforeBulkDestroy` hook stamps the column with a sibling UPDATE over the same still-live rows (same `where`, same transaction) just before the soft-delete sets `deletedAt`; `beforeBulkRestore` does the inverse, clearing it as `deletedAt` is cleared.

The sibling UPDATE runs on `this` — the concrete model the hook fires for, bound by Sequelize at call time (`runHooks` → `hook.apply(model, ...)`) — rather than the class captured at decoration time. That lets the decorator be declared on an abstract base model (e.g. a shared `BaseParanoid`) and still resolve to the real subclass; the captured constructor would be the (unregistered) base and break with "model not initialized".

`hooks: false` avoids hook re-entrancy and keeps the delete from bumping an `@UpdatedBy` column; `silent: true` keeps it from bumping `updatedAt`, so the delete writes exactly `deletedBy` + `deletedAt` (like the native paranoid delete writes only `deletedAt`). No-op when there is no acting user.

**Signature:**

```typescript
export declare function DeletedBy(target: any, propertyName: string): void;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| target | any | the decorated model's prototype |
| propertyName | string | the decorated column property name |


**Returns:**

void

