Adds two behaviours to Payload relationship fields through per-field custom config: cleaning up references when the target document is deleted, and keeping paired relationship fields on two collections in sync. It is registered as a plugin in the Payload config and works with the Mongo adapter only. Written for Payload 2.x and described as an early release.
Installation
npm i payload-relationship-enhancer12
Stars
0
Forks
3
Open Issues
2 years ago
Last Updated
895
Weekly Downloads
v0.0.10
npm Version
542.3 KB
Unpacked Size
1
Dependencies
120 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 12 |
| Dec 4, 2026 | 12 |
| Dec 3, 2026 | 12 |
| Dec 2, 2026 | 12 |
| Dec 1, 2026 | 12 |
| Nov 30, 2026 | 12 |
| Nov 29, 2026 | 12 |
| Nov 28, 2026 | 12 |
| Nov 27, 2026 | 12 |
| Nov 26, 2026 | 12 |
| Nov 25, 2026 | 12 |
| Nov 24, 2026 | 12 |
| Nov 23, 2026 | 12 |
| Nov 22, 2026 | 12 |
| Nov 21, 2026 | 12 |
| Nov 20, 2026 | 12 |
| Nov 19, 2026 | 12 |
| Nov 18, 2026 | 12 |
| Nov 17, 2026 | 12 |
| Nov 16, 2026 | 12 |
| Nov 15, 2026 | 12 |
| Nov 14, 2026 | 12 |
| Nov 13, 2026 | 12 |
| Nov 12, 2026 | 12 |
| Nov 11, 2026 | 12 |
| Nov 10, 2026 | 12 |
| Nov 9, 2026 | 12 |
| Nov 8, 2026 | 12 |
| Nov 7, 2026 | 12 |
| Nov 6, 2026 | 12 |
| Nov 5, 2026 | 12 |
| Nov 4, 2026 | 12 |
| Nov 3, 2026 | 12 |
| Nov 2, 2026 | 12 |
| Nov 1, 2026 | 12 |
| Oct 31, 2026 | 12 |
| Oct 30, 2026 | 12 |
| Oct 29, 2026 | 12 |
| Oct 28, 2026 | 12 |
| Oct 27, 2026 | 12 |
| Oct 26, 2026 | 12 |
| Oct 25, 2026 | 12 |
| Oct 24, 2026 | 12 |
| Oct 23, 2026 | 12 |
| Oct 22, 2026 | 12 |
| Oct 21, 2026 | 12 |
| Oct 20, 2026 | 12 |
| Oct 19, 2026 | 12 |
| Oct 18, 2026 | 12 |
| Oct 17, 2026 | 12 |
| Oct 16, 2026 | 12 |
| Oct 15, 2026 | 12 |
| Oct 14, 2026 | 12 |
| Oct 13, 2026 | 12 |
| Oct 12, 2026 | 12 |
| Oct 11, 2026 | 12 |
| Oct 10, 2026 | 12 |
| Oct 9, 2026 | 12 |
| Oct 8, 2026 | 12 |
| Oct 7, 2026 | 12 |
| Oct 6, 2026 | 12 |
| Oct 5, 2026 | 12 |
| Oct 4, 2026 | 12 |
| Oct 3, 2026 | 12 |
| Oct 2, 2026 | 12 |
| Oct 1, 2026 | 12 |
| Sep 30, 2026 | 12 |
| Sep 29, 2026 | 12 |
| Sep 28, 2026 | 12 |
| Sep 27, 2026 | 12 |
| Sep 26, 2026 | 12 |
| Sep 25, 2026 | 12 |
| Sep 24, 2026 | 12 |
| Sep 23, 2026 | 12 |
| Sep 22, 2026 | 12 |
| Sep 21, 2026 | 12 |
| Sep 20, 2026 | 12 |
| Sep 19, 2026 | 12 |
| Sep 18, 2026 | 12 |
| Sep 17, 2026 | 12 |
| Sep 16, 2026 | 12 |
| Sep 15, 2026 | 12 |
| Sep 14, 2026 | 12 |
| Sep 13, 2026 | 12 |
| Sep 12, 2026 | 12 |
| Sep 11, 2026 | 12 |
| Sep 10, 2026 | 12 |
| Sep 9, 2026 | 12 |
| Sep 8, 2026 | 12 |
| Sep 7, 2026 | 12 |
| Sep 6, 2026 | 12 |
1.1K+953 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 1,059 |
| Dec 4, 2026 | 940 |
| Dec 3, 2026 | 786 |
| Dec 2, 2026 | 565 |
| Dec 1, 2026 | 551 |
| Nov 30, 2026 | 551 |
| Nov 29, 2026 | 485 |
| Nov 28, 2026 | 259 |
| Nov 27, 2026 | 151 |
| Nov 26, 2026 | 104 |
| Nov 25, 2026 | 33 |
| Nov 24, 2026 | 33 |
| Nov 23, 2026 | 34 |
| Nov 22, 2026 | 80 |
| Nov 21, 2026 | 279 |
| Nov 20, 2026 | 315 |
| Nov 19, 2026 | 455 |
| Nov 18, 2026 | 622 |
| Nov 17, 2026 | 826 |
| Nov 16, 2026 | 826 |
| Nov 15, 2026 | 885 |
| Nov 14, 2026 | 907 |
| Nov 13, 2026 | 1,180 |
| Nov 12, 2026 | 1,441 |
| Nov 11, 2026 | 1,326 |
| Nov 10, 2026 | 1,123 |
| Nov 9, 2026 | 1,131 |
| Nov 8, 2026 | 1,076 |
| Nov 7, 2026 | 927 |
| Nov 6, 2026 | 724 |
| Nov 5, 2026 | 539 |
| Nov 4, 2026 | 733 |
| Nov 3, 2026 | 745 |
| Nov 2, 2026 | 998 |
| Nov 1, 2026 | 975 |
| Oct 31, 2026 | 1,648 |
| Oct 30, 2026 | 1,541 |
| Oct 29, 2026 | 1,324 |
| Oct 28, 2026 | 1,076 |
| Oct 27, 2026 | 1,063 |
| Oct 26, 2026 | 800 |
| Oct 25, 2026 | 848 |
| Oct 24, 2026 | 144 |
| Oct 23, 2026 | 136 |
| Oct 22, 2026 | 207 |
| Oct 21, 2026 | 256 |
| Oct 20, 2026 | 254 |
| Oct 19, 2026 | 254 |
| Oct 18, 2026 | 277 |
| Oct 17, 2026 | 280 |
| Oct 16, 2026 | 336 |
| Oct 15, 2026 | 312 |
| Oct 14, 2026 | 441 |
| Oct 13, 2026 | 440 |
| Oct 12, 2026 | 440 |
| Oct 11, 2026 | 379 |
| Oct 10, 2026 | 424 |
| Oct 9, 2026 | 452 |
| Oct 8, 2026 | 553 |
| Oct 7, 2026 | 402 |
| Oct 6, 2026 | 404 |
| Oct 5, 2026 | 404 |
| Oct 4, 2026 | 851 |
| Oct 3, 2026 | 942 |
| Oct 2, 2026 | 959 |
| Oct 1, 2026 | 882 |
| Sep 30, 2026 | 1,462 |
| Sep 29, 2026 | 2,010 |
| Sep 28, 2026 | 2,462 |
| Sep 27, 2026 | 2,020 |
| Sep 26, 2026 | 2,142 |
| Sep 25, 2026 | 2,206 |
| Sep 24, 2026 | 2,339 |
| Sep 23, 2026 | 2,037 |
| Sep 22, 2026 | 1,499 |
| Sep 21, 2026 | 1,134 |
| Sep 20, 2026 | 1,203 |
| Sep 19, 2026 | 986 |
| Sep 18, 2026 | 883 |
| Sep 17, 2026 | 722 |
| Sep 16, 2026 | 658 |
| Sep 15, 2026 | 646 |
| Sep 14, 2026 | 561 |
| Sep 13, 2026 | 439 |
| Sep 12, 2026 | 349 |
| Sep 11, 2026 | 287 |
| Sep 10, 2026 | 245 |
| Sep 9, 2026 | 5 |
| Sep 8, 2026 | 5 |
| Sep 7, 2026 | 7 |
| Sep 6, 2026 | 106 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/729925210-root)<a href="https://payloaddirectory.dev/plugins/729925210-root"><img src="https://payloaddirectory.dev/badge/729925210-root.svg" alt="Payload Directory"></a>README
This is a very early release of a plugin designed to enhance the relationships within payload to do two things:
referential integrity through deletes - i.e. if A references B and then B is deleted, A should no longer reference Abi-directional relationships - i.e. if A references B, allow B to reference A and keep them in sync.Motivation: if you have used keystonejs you know why, but more importantly, this stops gymnastics at query time to try and reverse lookup a relationship and instead builds it into the GraphQL / REST schema
This was written by someone who is bad at coding, and until a week ago had never used Mongo or Payload. Performance is probably bad and it might delete all your relationships.
I am almost certain this will not work properly for everyone and in every case, please leave an issue with details about how your relationships were setup!
Payload would appear to be considering bi-directional relationships as a core feature (although it is not on roadmap) in the future, so this should be seen as a stop-gap for applications prior to its official implementation.
bun add payload-relationship-enhancer
update your payload config like this:
import RelationshipEnhancerPlugin from "payload-relationship-enhancer";
plugins: [payloadCloud(), RelationshipEnhancerPlugin],
{
type: "relationship",
relationTo: "c",
hasMany: true,
name: "amixedblocks",
custom: {
relationshipEnhancer: {
relationshipIntegrity: true,
biDirectional: [
{
relationTo: "c", // must match one or more of the things in relationTo
path: "cmixedblocks", // this is the path of the field on c that is ALSO a relationship field AND has a biDirectional config pointing back here
},
...
],
},
},
},
{
relationshipIntegrity?: boolean,
biDirectional?: [
{
relationTo: string;
path: string;
},
...
],
}
Please do.
bun installbun run devMongo & payload will start - localhost:3000. Payload user is [email protected] with password test
payload collection references
Cascade-delete or unlink documents that reference a deleted Payload document
5310/wk2v3
payload db check
Admin view that finds duplicates, broken references and one-sided links, with opt-in previewed repairs
399/wk0v3
payloadcms relationships
List incoming and outgoing relationships for any Payload document via a synced relationships collection
101v2
payload dependency graph
Tracks dependencies between collections and globals so you know which content depends on which
032/wk14v2
payload locale snapshot
Prevents loss of other-locale translations in localized blocks and arrays when saving with the Postgres adapter
6663/wk3v3
payload seed
Type-safe database seeding for Payload with typed cross-file references and inline media uploads
57108/wk18v3