Skip to main content
TransactionDocument is a soft-deletable N:M join entity that links a Transaction to a Document (e.g. a bank-statement attachment or receipt). It lives in the core_api schema and mirrors the CompanyMedia / PersonMedia bridge-table shape. A partial unique index on (transaction_pk) WHERE deleted_at IS NULL enforces the current product invariant of one active attachment per transaction; a second transaction hard-delete CASCADE and a RESTRICT on the document side protect referential integrity. Workspace scope is inherited transitively through the Transaction relation — no direct workspace FK is declared on this table.
Internal object. Not currently exposed on the public REST API. The operations below describe the intended contract.

API operations

Data model

Attributes

Relationships

System-computed

  • pk — auto-increment serial primary key, internal join only; never exposed via public API.
  • created_at — set once on insert via onCreate: () => new Date() MikroORM hook.
  • deleted_at — set to current timestamp by the service layer on detach (soft-delete); never set by the user directly.
  • The partial unique index uq_transaction_documents_one_active_per_transaction on (transaction_pk) WHERE deleted_at IS NULL is enforced by Postgres at the DB layer — the service layer cooperates via a soft-delete-then-insert pattern on re-attach.
  • Workspace scope is inherited transitively through the Transaction relation; no explicit workspace_pk column exists on this table.

Example

Source: apps/api/src/database/entities/TransactionDocument.ts · domain: financial-graph · tier: Supporting