https://github.com/payloadcms/plugin-relationship-object-ids
A Payload plugin to store all relationship IDs as ObjectIDs
https://github.com/payloadcms/plugin-relationship-object-ids
payload-plugin
Last synced: 2 months ago
JSON representation
A Payload plugin to store all relationship IDs as ObjectIDs
- Host: GitHub
- URL: https://github.com/payloadcms/plugin-relationship-object-ids
- Owner: payloadcms
- License: mit
- Created: 2023-06-03T00:09:21.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T15:07:48.000Z (11 months ago)
- Last Synced: 2024-07-26T16:53:11.563Z (11 months ago)
- Topics: payload-plugin
- Language: JavaScript
- Homepage:
- Size: 308 KB
- Stars: 8
- Watchers: 5
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Payload Relationship ObjectID Plugin
This plugin automatically enables all Payload `relationship` and `upload` field types to be stored as `ObjectID`s in MongoDB.
Minimum required version of Payload: `1.9.5`
## What it does
It injects a `beforeChange` field hook into each `relationship` and `upload` field, which converts string-based IDs to `ObjectID`s immediately prior to storage.
#### Usage
Simply import and install the plugin to make it work:
```ts
import { relationshipsAsObjectID } from '@payloadcms/plugin-relationship-object-ids'
import { buildConfig } from 'payload/config'export default buildConfig({
// your config here
plugins: [
// Call the plugin within your `plugins` array
relationshipsAsObjectID()
]
})
```### Migration
Note - this plugin will only store newly created or resaved documents' relations as `ObjectID`s. It will not modify any of your existing data. If you'd like to convert existing data into an `ObjectID` format, you should write a migration script to loop over all documents in your database and then simply resave each one.
### Support
If you need help with this plugin, [join our Discord](https://t.co/30APlsQUPB) and we'd be happy to give you a hand.