Collection References
Automatically cascades deletes or unlinks relationship and upload fields across Payload collections when a referenced document is removed.
Installation
pnpm add @lizardglobal/payload-collection-references About
Payload lets a relationship or upload field keep pointing at a document that no longer exists. This plugin closes that gap. At config initialization it walks every targeted collection's field tree (including groups, tabs, and arrays) and records each `relationship` and `upload` field by its dot-notation path, then injects a `beforeDelete` hook on every collection that something else references. When a document is deleted, the hook queries all referencing collections and applies one of two strategies per field: `delete` cascade-removes the referencing documents (and re-triggers their own `beforeDelete` hooks recursively) or `unlink` sets the field to `null` or a custom `unlinkValue` while preserving the document. Auto-discovery defaults to `delete`; explicit declarations override the strategy per field. Configuration is small. Call `collectionReferencesPlugin()` with no arguments to apply to every collection, or pass `collections` for an allowlist, `exclude` for a blocklist, and `declarations` for per-field overrides with nested paths like `seo.ogImage`. A `disabled` flag turns the plugin into a no-op, useful for test environments. Circular references between collections are tracked through `req.context` to prevent infinite loops. For projects that want finer control, the core API is exported separately: `withCollectionReferences` wraps a single collection config, `finalizeCollectionReferences` resolves the set, and helpers like `getReferencesPointingTo`, `buildWhereForReferences`, and `groupReferencesByCollection` expose the internals. The plugin targets Payload `^3.84.1` and is explicitly experimental: collection schemas and behavior may change between releases, so pin versions deliberately.
Package info
- Package name
@lizardglobal/payload-collection-references- Latest version
1.0.1- Unpacked size
- 95 kB
- License
- MIT
- Last publish
- Aug 3, 2026
More from LizardGlobalGH
View profileDiscord Sync
Syncs Discord guilds, channels, members, and roles into Payload collections on demand, over HTTP, or on a cron schedule via discord.js.
Rich Text Lexical React Native
Renders serialized Lexical rich text from Payload CMS in React Native apps using native primitives with overridable converters.
Dry Run
Test Payload create operations end-to-end without persisting, by rolling back the transaction after hooks and validation run.
Similar plugins
More in ContentKanban Board
A kanban board plugin for managing tasks in Payload CMS.
versioning
This plugin enables easy versioning for Payload collections.
Shiki Code
Integrates Shiki syntax highlighting for code blocks in Payload CMS.
Callouts
Create styled callout blocks with customizable themes for Payload CMS.
Tree list view
This plugin adds a collapsible tree list view to Payload CMS.
Export Collections
This plugin allows exporting collections data to CSV or JSON formats.