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.2- Unpacked size
- 77 kB
- License
- MIT
- Weekly downloads
- 7
- Last publish
- Aug 4, 2026
More from LizardGlobalGH
View profileRich 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.
Discord Sync
Syncs Discord guilds, channels, members, and roles into Payload collections on demand, over HTTP, or on a cron schedule via discord.js.
Similar plugins
More in ContentPresets
Save and apply reusable block configurations as presets in the Payload admin panel.
AI Plugin
Integrates AI capabilities for content generation in Payload CMS.
Nested Docs Page Tree
Adds a nested tree view for managing documents in Payload CMS.
Nested Docs
Adds parent-child document hierarchies with auto-generated breadcrumbs to Payload collections.
Redirects
Manage redirects directly within the Payload CMS admin panel.
Reservation and Booking Manager
Manage reservations and bookings through Payload CMS with conflict detection and scheduling.